我正在用一个管道创建一个视觉跟踪程序。在我的管道中,我有以下代码:
@staticmethod
def __approx_contours(input_contours):
output = []
kp = None
for contour in input_contours:
error = 0.1*cv2.arcLength(contour, True)
approx = cv2.approxPolyDP(contour, error, True)
print(approx)
kp = Keeper(approx)
print(kp)
if kp == None:
return output
for x,y in zip(kp.getX(),kp.getY()):
output.append((x,y))
kp.empty()
return output
这里是守门员班
^{pr2}$忽略__init__
中的print语句,它们仅用于调试目的。在
当前状态下的输出示例:
[[[183 169]]
[[187 323]]]
Keeper
[183, 187]
[169, 323]
<keeper.Keeper object at 0x05199630>
[[[ 62 117]]
[[ 93 366]]
[[187 256]]]
Keeper
[183, 187, 62, 93, 187]
[169, 323, 117, 366, 256]
<keeper.Keeper object at 0x06F10B70>
似乎我的Keeper对象中的值没有被重置,尽管调用了kp.空(). 我还注意到Keeper对象在内存中的位置正在改变,也许这是问题的一部分,但我不确定我哪里出错了。完整代码可用here
问题是作为用户@胡安帕.阿里维拉加我使用的是类属性而不是实例属性。要解决我的问题,需要对Keeper进行以下更改:
相关问题 更多 >
编程相关推荐