OpenCV cv2.HoughCircles检测在简单图片上给出不好的结果

时间:2018-06-28 23:19:47

标签: opencv geometry detection hough-transform cv2

我是opencv的新手,我正尝试使用HoughCircles进行圆检测,但是它给了我没有圆的圆,也没有检测到我想要的巨大圆。我尝试更改参数,但无法使其正常运行。我在做什么错了?

原始图片: Original Image

阈值化后的图像: Image After Thresholding

Canny用圈子过滤: enter image description here

path=r"minimap.png"
screen = cv2.imread(path,cv2.IMREAD_GRAYSCALE)
cv2.imshow('Original', screen)

ret,screen = cv2.threshold(screen,200,255,cv2.THRESH_BINARY)
cv2.imshow('Thresholded', screen)

P=50
can = cv2.Canny(screen,P/2,P)
cv2.imshow('Canny', can)

if 1:
    circles = cv2.HoughCircles(screen, cv2.HOUGH_GRADIENT, dp=1, minDist=50, param1=P, param2=53, minRadius=0, maxRadius=0)
    print(circles)

    circles = np.uint16(np.around(circles))
    can=cv2.cvtColor(can,cv2.COLOR_GRAY2RGB)
    for i in circles[0,:]:
        # draw the outer circle
        cv2.circle(can, (i[0], i[1]), i[2], (0, 255, 0), 3)
        # draw the center of the circle
        cv2.circle(can, (i[0], i[1]), 2, (0, 0, 255), 5)

cv2.imshow('Circles', can)
cv2.waitKey()

1 个答案:

答案 0 :(得分:0)

您必须使用Column A, Column B, Column C, Sum(D) ValueA1 , , , 3 , ValueB1 , , 1 , , ValueC1 , 1 , ValueB2 , , 2 , , ValueC2 , 2 参数,但我认为相同的值不能为所有图像带来良好的效果。对于您的图片:

cv2.HoughCircles

result