Ask Your Question
0

How does the minimum distance for Houghcircles work?

asked 2020-03-02 02:49:19 -0600

fabiomirisola gravatar image

updated 2020-03-02 07:34:07 -0600

supra56 gravatar image

I'm using openCV to detect circles generated by me. But while setting the parameters right I get alot of overlapping circles drawn. I've set minDist to everything but it will not work.

circles = cv2.HoughCircles(image,3,cv2.HOUGH_GRADIENT,1,minDist=50,param1=800,param2=20,minRadius=0,maxRadius=25)

C:\fakepath\generated.jpg

C:\fakepath\detected.jpg

edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted
0

answered 2020-03-02 10:07:58 -0600

supra56 gravatar image

updated 2020-03-02 10:09:15 -0600

I solved a little problem. I merely got 90 out of 100 circles. Unfortunately, I can't used your snipped code as above. I can't go beyond values. Fortunately, you can modified to suit your needed. There are no noises in background.

#!/usr/bin/python3.7.3
#OpenCV 4.2, Raspbery pi 3/3b/34b, Buster ver 10, Thonny 3.7.3
#Date: 2nd March, 2020

import numpy as np
import cv2 as cv

def main():
    fn = 'circles.jpg'

    src = cv.imread(fn)
    img = cv.cvtColor(src, cv.COLOR_BGR2GRAY)
    #img = cv.medianBlur(img, 9)
    cimg = src.copy() # numpy function

    ret, thresh = cv.threshold(img, 127, 255, cv.THRESH_BINARY_INV)

    circles = cv.HoughCircles(thresh,   cv.HOUGH_GRADIENT,1, 20, np.array([]), 80, 12, 4, 25)

    counter = 0
    if circles is not None: # Check if circles have been found and only then iterate over these and add them to the image
        _a, b, _c = circles.shape
        for i in range(b):
            cv.circle(cimg, (circles[0][i][0], circles[0][i][1]), circles[0][i][2], (0, 0, 255), 2, cv.LINE_AA)
            cv.circle(cimg, (circles[0][i][0], circles[0][i][1]), 2, (0, 255, 0), 3, cv.LINE_AA)  # draw center of circle
            counter += 1

        print(f'counter ;', counter)
        cv.imshow("detected circles", cimg)
        cv.imwrite('detected_circles.jpg', cimg)

    cv.imshow("source", src)
    cv.waitKey(0)
    print('Done')

if __name__ == '__main__':
    main()
    cv.destroyAllWindows()

Output:

image description

edit flag offensive delete link more

Comments

1

Thank you very much!

fabiomirisola gravatar imagefabiomirisola ( 2020-03-03 03:24:57 -0600 )edit

Question Tools

1 follower

Stats

Asked: 2020-03-02 02:49:19 -0600

Seen: 683 times

Last updated: Mar 02 '20