OpenCV3 圆检测 - 如何查找简单圆(未找到明显的解决方案)

问题描述 投票:0回答:1

这是一个简单的图像,它具有与灰度图像相同大小和硬边缘的斑点。为什么下面的代码找不到这些圆圈?

ret,thresh1 = cv2.threshold(img,180,250,cv2.THRESH_BINARY)
thresh1 = cv2.blur(thresh1,(15,15))
circles = cv2.HoughCircles(thresh1,cv2.HOUGH_GRADIENT, 2, np.shape(thresh1)[0]/8, param1=200, param2=10)
if circles is not None:
    plt.imshow(np.flipud(thresh1), origin='lower', cmap='bone')
    circles = np.uint16(np.around(circles))
for i in circles[0,:]:
    currentAxis = plt.gca()
    currentAxis.add_patch(Circle((i[0] , i[1]), i[2],fill=False,color='red'))
    currentAxis.add_patch(Circle((i[0] , i[1]), 8,fill=True,color='green'))
plt.show()

Simple Blobs Not Detected

我得到的输出是这样的:

Detection Not Correct

我尝试调整 param1 和 param2。要么我最终得到错误检测(不止这个),要么什么也没有!最小距离参数仅设置为图像宽度的 1/8 作为任意值。

python geometry opencv3.0 hough-transform
1个回答
1
投票

图像被翻转(np.flipud)并将原点设置为底部 - 这是该项目下一阶段的一部分,但我只是没有发现它!这段代码工作正常。

ret,thresh1 = cv2.threshold(img,180,250,cv2.THRESH_BINARY)
thresh1 = cv2.blur(thresh1,(15,15))
circles = cv2.HoughCircles(thresh1,cv2.HOUGH_GRADIENT, 1.2, minDist = 10,    param1=200, param2=50, minRadius = 0, maxRadius = 100)
if circles is not None:
    plt.imshow((thresh1), cmap='bone')
    circles = np.uint16(np.around(circles))
for i in circles[0,:]:
    currentAxis = plt.gca()
    currentAxis.add_patch(Circle((i[0] , i[1]), i[2],fill=False,color='red'))
    currentAxis.add_patch(Circle((i[0] , i[1]), 8,fill=True,color='green'))
plt.show()

产生以下结果: enter image description here

感谢您的帮助;-)

© www.soinside.com 2019 - 2024. All rights reserved.