2

I want to find the circles in the below image.I tried using OpenCV's Hough circle detection but it is not giving the proper results.

Is there any other way to find circles?

enter image description here

Here is sample code

vector<Vec3f> circles;
Mat src_gray,te; 
cvtColor(tImg, src_gray, CV_BGR2GRAY);
GaussianBlur(src_gray, src_gray, Size(9, 9), 2, 2);
Canny(src_gray, te, 40, 240, 3);
/// Apply the Hough Transform to find the circles 
HoughCircles(te, circles, CV_HOUGH_GRADIENT, 1, te.rows / 10, 120, 9, 5, 25); 
Bull
  • 11,771
  • 9
  • 42
  • 53
Rahul galgali
  • 775
  • 2
  • 10
  • 26
  • I suppose the Hough circle transform isn't finding any circles because there aren't any circles in that image. They're not really circles are they. You could try Hough ellipse, there is some code here but I don't know if it is any good: http://toyhouse.cc/profiles/blogs/modified-hough-ellipse-transform-detecting-ellipse-in-an-accurate . Alternatively, you could resize the image so that those circles look more like circles. – Bull Jul 18 '14 at 09:22
  • If a image is taken from a mobile or say any low resolution pic..the results are random but if it is generated in paint or msWord then it detects properly. – Rahul galgali Jul 18 '14 at 09:26
  • Can you 1. post your code, 2. post a pic that works. Phone pics may be noisy and need a Gaussian filter, although above pic doesn't look noisy. – Bull Jul 18 '14 at 09:31
  • I have done some resizing http://i.imgur.com/g1Rx9Xc.png Still its giving me less no if circles – Rahul galgali Jul 18 '14 at 09:32
  • Here is sample code vector circles; Mat src_gray,te; cvtColor(tImg, src_gray, CV_BGR2GRAY); GaussianBlur(src_gray, src_gray, Size(9, 9), 2, 2); Canny(src_gray, te, 40, 240, 3); /// Apply the Hough Transform to find the circles HoughCircles(te, circles, CV_HOUGH_GRADIENT, 1, te.rows / 10, 120, 9, 5, 25); – Rahul galgali Jul 18 '14 at 09:34
  • HoughCircle internally uses SOBEL gradient computation, that's why line input might not be so good. You could implement a RANSAC circle detection yourself. See both of my answers to http://stackoverflow.com/questions/20698613/detect-semi-circle-in-opencv – Micka Jul 18 '14 at 09:49
  • I was trying other ways to do it..lets say I find out contours the result is something like this.. http://i.imgur.com/P8pPljd.png Now my nxt challange is to delete those concentric circles. – Rahul galgali Jul 18 '14 at 11:01
  • http://stackoverflow.com/questions/4785419/detection-of-coins-and-fit-ellipses-on-an-image Hope this answers your question – Balaji R Jul 18 '14 at 12:41

1 Answers1

1

Take contour,
1. find the centroid of the contour
2. find distance from the centroid to each contour pixels.
3. if this distance is almost same then it will be a circle.

See This link

Community
  • 1
  • 1
Deepak
  • 1,038
  • 5
  • 17
  • 44