[Python] Improving speed and robustnes for opencv HoughCircles for only single circle

Discussão em 'Python' iniciado por Stack, Setembro 26, 2024.

  1. Stack

    Stack Membro Participativo

    There are many threads on how to detect multiple circles via OpenCV's HoughCircles function, and I understand that this is a complex task with no single good answer. However, maybe someone can give some hints for parameters for the specific problem of only finding a single circle. I also want to only get an answer when the algorithm is sure enough, so no 'maybe', please. The data sometimes has a background of 100-150 (out of 255) with the signal peaking all the way to >200 for most of the time. Does the function handle offsets well or would it be worth to spend some time to remove the background?

    My current code:

    im8blur = cv2.blur(im8, (n, n))


    or

    im8blur = cv2.GaussianBlur(im8, (n,n), cv2.BORDER_DEFAULT)


    with n in the range of 3-10 for the first case or >30 for the second case.

    Then, with these parameters, the results are best, but it takes >20 minutes for 140 images...

    detected_circles = cv2.HoughCircles(im8blur,
    cv2.HOUGH_GRADIENT, 1,
    minDist = 2000,
    param1 = 14,
    param2 = 4,
    minRadius = 400,
    maxRadius = 600)


    My circles are all around 520px in radius, but setting the minRadius to 500 or setting the maxRadius to -1 yielded worse results.

    For my 1400x1400 pictures, I picked a 2000 minDist to ensure only one circle to be found.

    However, I still get mixed results. Only when it is super clear, I get a good fit, but most of the time a circle is places somewhere.

    For the case of only one circle, there must be a better solution...?

    Continue reading...

Compartilhe esta Página