Attention! This forum will be made read-only by Dec-20. Please migrate to https://forum.opencv.org. Most of existing active users should've received invitation by e-mail.

# 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),
Math.round(vCircle));
// 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

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

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

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