# hough circle

How can I get the number of circles that return by hough circle using java open CV.

Mat circles = new Mat();

Imgproc.HoughCircles(grayImage, circles, Imgproc.CV_HOUGH_GRADIENT, 1 , gray.rows()/2 , 200, 20, 30, 0 );

System.out.println("#rows " + circles.rows() + " #cols " + circles.cols());


I don't know how it store the circles in Mat that has cols and rows ??

I try to get the circle from column but it does not work !!!

if (circles.cols() > 0)
for (int x = 0; x < circles.cols(); x++)
{
double vCircle[] = circles.get(0,x);
if (vCircle == null)
break;
Point pt = new Point(Math.round(vCircle[0]),
Math.round(vCircle[1]));
// draw the found circle
Core.circle(imgRGB, pt, radius, new Scalar(0,255,0), 2);
Core.circle(imgRGB, pt, 3, new Scalar(0,255,0), 2);
}


For example look at this image

edit retag close merge delete

1

Have you seen this?

( 2015-10-06 05:01:50 -0600 )edit

Strange... I'll go for a grouping circle custom function... Maybe using groupRectangles?

( 2015-10-06 09:46:54 -0600 )edit

Thank u :)

( 2015-10-07 05:47:42 -0600 )edit

Did this solve the problem? If so I am going to combine some answers so you can mark this solved.

( 2015-10-07 05:55:03 -0600 )edit

YES I increase the min distance as u said :)))

( 2015-10-07 06:12:46 -0600 )edit

Do mark it as solved :) Thank you!

( 2015-10-07 06:37:38 -0600 )edit

Sort by ยป oldest newest most voted

Copied from @thdrksdfthmn:

I would try to do a mean of the circles if their ratios are almost the same and the distances between the centers is less than the ratio. But have you tried to play with min_dist parameter? I have seen that you have set it to 10, why?

Increase the min_dist parameter for the circles centers as said by @thdrksdfthmn. It is the distance between two neighboring circle centers. Keep in mind that all edges in an image contribute to a possible circle, that is why HoughCircles always finds more circles than we need if you do not adapt the parameters correctly.

more

Official site

GitHub

Wiki

Documentation