我试图运行以下代码:
if (numObj<Max_DetObj):
i=0
while (i >= 0).all():
Moment = cv2.moments(contours[i])
area = Moment['m00']
if (area >Min_ObjArea):
x=Moment['m10']/area
y=Moment['m01']/area
found_Obj=True
else:
found_Obj=False
i=hierarchy[i][0]
但我有个错误:
Traceback (most recent call last):
File "C:\opencv2.4.8\sources\samples\python2\Work.py", line 120, in <module>
trackObj(threshold,hsv,frame)
File "C:\opencv2.4.8\sources\samples\python2\Work.py", line 84, in trackObj
while i >= 0:
ValueError: The truth value of an array with more than one element is ambiguous. Use a.any() or a.all()
当我在特定行中添加all()或any()时,会出现以下错误:
AttributeError: 'bool' object has no attribute 'all'
有人能解释吗?!!
i
是一个list
。我们没有关于它所包含内容的信息,但是错误和解决方案仍然很清楚。对于参数,假设
i
是:不能将列表与
>=
进行比较。相反,您要做的是比较列表中的每个元素。因为你比较的是>= 0
,用any()
和all()
来检查它的真实性就足够简单了:所以在你的代码中,应该是:
或者
只有您知道应该是哪一个,这取决于您是否要检查它们是否全部>;=0,或者只检查一个就足够了。
^{} :
^{} :
我猜你在使用numpy数组卧底,所以你应该使用numpy函数。
请参阅复制stacktrace的代码:
相关问题 更多 >
编程相关推荐