[Python] OpenCV3 Circle Detection - How to Find Simple Circles (Obvious solutions not being...

Discussão em 'Python' iniciado por Stack, Maio 10, 2025.

  1. Stack

    Stack Membro Participativo

    Here is a simple image that has blobs of the same size and hard edge, as a greyscale image. Why does the code below not find these circles?

    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()


    [​IMG]

    The output that I got is this:

    [​IMG]

    I've tried tweaking the param1 and param2. Either I end up with false detections (more than this) or nothing at all! The minimum distance parameter is set to 1/8th the width of the image only as an arbitrary value.

    Continue reading...

Compartilhe esta Página