gpt4 book ai didi

python - 从移动对象中获取的点列表

转载 作者:太空宇宙 更新时间:2023-11-03 21:08:15 25 4
gpt4 key购买 nike

我在从屏幕上移动的 block 的中心访问存储的 x、y 坐标列表时遇到了一些问题。我已经能够成功获取每一帧的 block 的 x 和 y 坐标,但在存储此信息然后无法在某些阶段访问该点时遇到问题。我的目标是能够将这些点连接在一起形成一条轨迹。低于我目前拥有的。

类定义:

    class People:

def __init__(self):
self.x = 0
self.y = 0

假设在检测到中心的每个点,cX 和 cY 都正确更新。

    MultPeople=[]

以下内容属于逐帧遍历视频的循环

    Person=People()
Person.x=cX
Person.y=cY
MultPeople.append(Person)

但现在当我想按顺序访问这些点以连接点时,我一次只能得到一个点,因此我无法做到。

    for index,man in enumerate(MultPeople):
print (index,man.x,man.y)
xplot=man.x
yplot=man.y
cv2.circle(frame1, (xplot, yplot), 2, [50, 20, 255], 3)

这样就成功在原图的中心点画了一个圆,但是答案是这样返回的

    (0, 306, 379)
(0, 307, 377)
(0, 307, 384)
(0, 305, 396)
(0, 309, 409)
(0, 310, 431)

为了获得索引的值需要添加什么,我假设这是为了访问某些点所需要的。

我也是在打印index,man.x,man.y后输入了下面这行

        print np.size(MultPeople)

它每次都打印回 1,因此我认为问题出在 append 函数上,因为它不是每次都向列表中添加新值,但我不确定应该如何更正。

最佳答案

将更新循环中的所有代码“按原样”不间断地发布到打印循环中,因为很难看到这样的问题。但据我所知——您可能在更新循环中创建、更新和打印了列表,如下所示:

while condition:
MultPeople=[]
Person=People()
# Here you somehow get the new cX and cY values
Person.x=cX
Person.y=cY
MultPeople.append(Person)
for index,man in enumerate(MultPeople):
print (index,man.x,man.y)
xplot=man.x
yplot=man.y
cv2.circle(frame1, (xplot, yplot), 2, [50, 20, 255], 3)

因此列表 MultPeople 被创建, append 了一项,然后 for 循环遍历列表中的一项(即它只执行一次,使用 index == 0 and size of 1) 然后你会收到你的结果。

也就是说,如果我的猜测是正确的。您真的应该按原样发布代码,将它切成碎片阅读真的很难。

如果是这种情况,您真正想要的是:

MultPeople=[]
while condition:
Person=People()
# Here you somehow get the new cX and cY values
Person.x=cX
Person.y=cY
MultPeople.append(Person)
for index,man in enumerate(MultPeople):
print (index,man.x,man.y)
xplot=man.x
yplot=man.y
cv2.circle(frame1, (xplot, yplot), 2, [50, 20, 255], 3)

关于python - 从移动对象中获取的点列表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38010161/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com