Ask Your Question

Revision history [back]

i suggest you to use ED_Lib which finds circles and ellipses efficiently. I want to add it in OpenCV Contrib but did not find enough time to complete yet. anyway i can help you if you want to add its source in OpenCV and use it with python.

image description

i suggest you to use ED_Lib which finds circles and ellipses efficiently. I want to add it in OpenCV Contrib but did not find enough time to complete yet. anyway i can help you if you want to add its source in OpenCV and use it with python.

you can test it if you compile OpenCV adding edlib directory in modules

sample python code produces the image below:

image description

import cv2

img = cv2.imread('16016470376420309.jpg')
circles = cv2.testEDCircles(img)
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):
            cv2.circle(img, (circles[0][i][0], circles[0][i][1]), circles[0][i][2], (0, 255, 0), 1, cv2.LINE_AA)
            cv2.circle(img, (circles[0][i][0], circles[0][i][1]), 2, (0, 255, 0), 1, cv2.LINE_AA)  # draw center of circle
# show the output image
cv2.imshow("output", img)
cv2.waitKey(0)
cv2.destroyAllWindows()