Why the arc results with opencv hough circle so different?

81 views Asked by At

There are two binary images about lines and arcs. The first is the original image, and the second one has changed the height of the original image and filled it with black. The arc has not changed. And then call opencv hough circle detection function with the two images. The parameters are the same, but the results are very different. It seems that the detection results are related to the image size. I took a cursory look at the relevant source code of opencv and could not find the reason. I'm confused, please help me, thank you very much!

result image 1: result image 1

result image 2: result image 2

Test with opencv-python 4.8.0.76

My test code here

import cv2
import numpy as np

if __name__ == '__main__':
    mask = cv2.imread(r'new\07.jpg', 0)
    circles = cv2.HoughCircles(mask, cv2.HOUGH_GRADIENT, dp=1, minDist=10, param1=200, param2=9, minRadius=0, maxRadius=0)
    circles = circles.astype(np.int32)

    show_circle = mask.copy()
    show_circle = cv2.cvtColor(show_circle, cv2.COLOR_GRAY2BGR)
    max_n = 1
    for cnt, i in enumerate(circles[0, :]):
        center = (i[0], i[1])
        radius = i[2]
        cv2.circle(show_circle, center, radius, [0, 255, 0], 2)
        print(f'radius = {radius}')
        if cnt >= max_n-1:
            break

    # Save image
    cv2.imwrite(f"output/circle.png", show_circle)

Test images here ori image changed image

0

There are 0 answers