Ferenc Dajka Ferenc Dajka - 1 year ago 168
Java Question

Find circles image processing

I'm using opencv and java to find circles on an image, I have the image below so far.
I'm using Hough to find the circles with the code like this:

Imgproc.medianBlur(result, result, 3);
Imgproc.medianBlur(result, result, 3);
Imgproc.medianBlur(result, result, 3);
Mat circles = new Mat();
Imgproc.HoughCircles(result, circles, Imgproc.CV_HOUGH_GRADIENT, 1, 1, 200, 100, 30, 40);

But I get an empty Mat for result with and without the blur.
How should I fix this code?

enter image description here

Hi guys!

Thanks to you I have this picture now. I'm using these parameters:

Imgproc.HoughCircles(result, circles, Imgproc.CV_HOUGH_GRADIENT, 1, 20, 50, 10, 10, 40);

I'm still using the medianBlur before the detection.

The only question left is why does it detect these small circles? I've attached the result of the canny detection, I think the circles are pretty seeable .

enter image description here
enter image description here

Answer Source

First of all, the circles structure should not be cv::Mat but should be std::vector<cv::Vec3f>; I think that is why you aren't getting any results.. Please refer to the documentation on the HoughCircles for details..

Playing around with the values for 5 minutes, I have this starting point for you:

enter image description here

The parameters I used are,

cv::medianBlur(test_Circle, test_Circle, 7);
std::vector<cv::Vec3f> circles; // <- not that "circles" is not cv::Mat
cv::HoughCircles(test_Circle, circles, CV_HOUGH_GRADIENT, 1, 1, 300, 10, 10, 50);

You can get much more defined result after you played around with the values a bit.

PS - Since I am a C++ user, please excuse me for putting all my structures in that format. You can easily extend the logic to Java. :)

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download