[英]OpenCV Hough Circle Transform Not Working
I have followed OpenCV's tutorial here for circle detection on my Raspberry Pi. 我已在此处按照OpenCV的教程在 Raspberry Pi上进行圆圈检测。 This is the code that I am using which is the same as the tutorial except a different image. 这是我使用的代码,与本教程相同,只是图像不同。
import cv2
import numpy as np
img = cv2.imread('watch.jpg',0)
img = cv2.medianBlur(img,5)
cimg = cv2.cvtColor(img,cv2.COLOR_GRAY2BGR)
circles = cv2.HoughCircles(img,cv2.HOUGH_GRADIENT,1,20,
param1=50,param2=30,minRadius=0,maxRadius=0)
circles = np.uint16(np.around(circles))
for i in circles[0,:]:
cv2.circle(cimg,(i[0],i[1]),i[2],(0,255,0),2)
cv2.circle(cimg,(i[0],i[1]),2,(0,0,255),3)
cv2.imshow('image',cimg)
cv2.waitKey(0)
cv2.destroyAllWindows()
Then when I ran the script this is what I was presented with this 然后,当我运行脚本时,这就是我所看到的
and this is the original image 这是原始图像
What is causing this to happen? 是什么导致这种情况发生?
Thank You in Advance! 先感谢您!
Edit: 编辑:
The large amount of circles generated by Hough Circle Transform is caused by the low value of the threshold for center detection, which is param2
in cv2.HoughCircles
in your case. Hough Circle Transform生成的大量圆是由中心检测阈值的较低值引起的,该阈值在cv2.HoughCircles
中为param2
。
So try to increase the value of param2
to avoid false detections. 因此,请尝试增加param2
的值,以避免错误检测。
Also you can adjust minRadius
and maxRadius
values for better results. 您也可以调整minRadius
和maxRadius
值以获得更好的结果。
EDIT: 编辑:
I have just tried example from here and changed only param2
to 10
, minRadius
to 30
and maxRadius
to 50
. 我只是从这里尝试过示例,仅将param2
更改为10
,将minRadius
为30
,将maxRadius
为50
。 The result is good enough: 结果足够好:
The example from the link above is written with C++ , but you can compare parameters and the sequence of functions invocations to refine your own algorithm. 上面链接中的示例是使用C ++编写的,但是您可以比较参数和函数调用的顺序以完善自己的算法。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.