[numpy问题]The truth value of an array with more than one element is ambiguous.
程序员文章站
2022-05-27 12:46:12
...
问题描述:在进行Hough圆变换时,需要输出一个圆的坐标:
circles = cv2.HoughCircles(canny, cv2.HOUGH_GRADIENT, 2, 40, param1=30, param2=30, minRadius=0, maxRadius=20)
接下来会根据这个圆的坐标来画圆心:
for circle in circles[0]:
x=int(circle[0])
y=int(circle[1])
r=int(circle[2])
#crop = img.copy()
crop=cv2.circle(crop,(x,y),r,(255,255,255),1)
crop = cv2.circle(crop, (x, y), 1, (255, 255, 255), -1)
cv2.imshow("crop", crop)
这时候如果hough圆变换没有检测出来圆的话会报错会显示circles是NoneType,如果加一个判定
if circles!=None:
则会报错ValueError: The truth value of an array with more than one element is ambiguous. Use a.any() or a.all()
意思上一个判断语句有些模棱两可,circles是很多个圆,不一定所有的都是NoneType。
根据提示修改判断语句为:
if np.all(circles!=None):
for circle in circles[0]:
x=int(circle[0])
y=int(circle[1])
r=int(circle[2])
#crop = img.copy()
crop=cv2.circle(crop,(x,y),r,(255,255,255),1)
crop = cv2.circle(crop, (x, y), 1, (255, 255, 255), -1)
cv2.imshow("crop", crop)
表示circles里面所有的圆都不是Nonetype格式时,判断为真。解决掉了这个bug。
上一篇: Linux安装mysql5.6
下一篇: 学习随笔-ValueError: The truth value of an array with more than one element is ambiguous
推荐阅读
-
moviepy AudioClip帧处理ValueError: The truth value of array with more than one element is ambiguous
-
python报错ValueError: The truth value of an array with more than one element is ambiguous. Use a.any()
-
Python报错:The truth value of an array with more than one element is ambiguous
-
Python ValueError: The truth value of an array with more than one element is ambiguous.
-
成功解决Python的ValueError: The truth value of an array with more than one element is ambiguous
-
moviepy AudioClip帧处理ValueError: The truth value of array with more than one element is ambiguous
-
[numpy问题]The truth value of an array with more than one element is ambiguous.
-
学习随笔-ValueError: The truth value of an array with more than one element is ambiguous
-
ValueError: The truth value of an array with more than one element is ambiguous. Use a.any() or
-
moviepy AudioClip帧处理ValueError: The truth value of array with more than one element is ambiguous