mrgloom
mrgloom

Reputation: 21622

Find all circle objects

I'm trying to find all circle objects on image using python wrapper for opencv. Something like this.

Using cv2.HoughCircles but I can't find optimal parameters. Is it possible at all?

My code:

import cv, cv2
import numpy as np

im = cv2.imread("C:/1.jpg")

grey = cv2.cvtColor(im, cv.CV_RGB2GRAY)
blur= grey
#blur = cv2.GaussianBlur(grey, (0,0), 10)
circles =  cv2.HoughCircles(blur, cv2.cv.CV_HOUGH_GRADIENT, 2, 5, np.array([]), 40, 80, 5, 50)#params?
if circles is not None:
        for c in circles[0]:
                cv2.circle(im, (c[0],c[1]), c[2], (0,255,0),2)
edges = cv2.Canny( blur, 40, 80 )

cv2.imwrite("C:/circle.jpg",im)
cv2.imwrite("C:/canny.jpg",edges)

enter image description here

enter image description here

Upvotes: 2

Views: 1446

Answers (1)

Mailerdaimon
Mailerdaimon

Reputation: 6080

This is not an easy task regarding the image you provided.

Try to find a good range for your radius (minRadius,maxRadius: not to big, otherwise some small circles well be seen as one big circle) too improve your result.

Otherwise i would suggest seperating the Objects with another approach (watershedding for example)

Upvotes: 1

Related Questions