错误提示:
modules\imgproc\src\hough.cpp:2267: error: (-211:One of the arguments’ values is out of range) acc_threshold must be a positive number in function ‘cv::HoughCircles
#VX公众号: 桔子code / juzicode.com
import numpy as np
import cv2
print('cv2.__version__:',cv2.__version__)
img_src = cv2.imread('opencv-logo.png',0)
circles = cv2.HoughCircles(img_src,cv2.HOUGH_GRADIENT,dp=1,minDist=20,param1=50,param2=-1,minRadius=0,maxRadius=0)
print('circles.shape:',circles.shape)
print('circles:\n',circles)
==========运行结果:---------------------------------------------------------------------------
error Traceback (most recent call last)
<ipython-input-7-79e0dfc9824b> in <module>
4 print('cv2.__version__:',cv2.__version__)
5 img_src = cv2.imread('opencv-logo.png',0)
----> 6 circles = cv2.HoughCircles(img_src,cv2.HOUGH_GRADIENT,dp=1,minDist=20,param1=50,param2=-1,minRadius=0,maxRadius=0)
7 print('circles.shape:',circles.shape)
8 print('circles:\n',circles)
error: OpenCV(4.5.3) E:\juzicode\opencv-4.5.3\modules\imgproc\src\hough.cpp:2267: error: (-211:One of the arguments' values is out of range) acc_threshold must be a positive number in function 'cv::HoughCircles'
错误原因:
1、HOUGH_GRADIENT方法找圆时param2表示的acc-threashold参数必须大于0.
解决方法:
1、param2参数设置为大于0的值
#VX公众号: 桔子code / juzicode.com
import numpy as np
import cv2
print('cv2.__version__:',cv2.__version__)
img_src = cv2.imread('opencv-logo.png',0)
circles = cv2.HoughCircles(img_src,cv2.HOUGH_GRADIENT,dp=1,minDist=20,param1=50,param2=30,minRadius=0,maxRadius=0)
print('circles.shape:',circles.shape)
print('circles:\n',circles)
==========运行结果:
cv2.__version__: 4.5.3
circles.shape: (1, 22, 3)
circles:
[[[143.5 415.5 141.2]
[297.5 139.5 54.7]
[451.5 414.5 135.7]
[160.5 403.5 161.7]
[472.5 417.5 123.4]
[ 61.5 644.5 60.7]
[346.5 665.5 44.4]
[161.5 426.5 117.3]
[445.5 436.5 115.1]
[445.5 645.5 61.5]
[404.5 672.5 83.8]
[170.5 662.5 41.2]
[248.5 650.5 36.6]
[452.5 665.5 61.2]
[132.5 438.5 115.4]
[ 44.5 624.5 39.6]
[ 42.5 656.5 47.9]
[ 56.5 672.5 67.8]
[469.5 646.5 62.1]
[442.5 625.5 60. ]
[421.5 656.5 46.2]
[245.5 672.5 35.2]]]
扩展内容:
如果本文还没有完全解决你的疑惑,你也可以在微信公众号“桔子code”后台给我留言,欢迎一起探讨交流。