Ferenc Dajka
Ferenc Dajka

Reputation: 1051

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);
    System.out.println(circles.dump());

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

enter image description here

EDIT : 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

Upvotes: 2

Views: 2248

Answers (3)

JKing
JKing

Reputation: 11

I've tested my code, it writtent in C# (i think java is the same) and get the result:1

You can find my code in HoughAlgorithm.cs class My demo Project Here

    //DP_Resolution: 1
//MinDistance :32
//CannyThreshold: 10
//AccuThreshold: 10
//MinRadius: 13
//MaxRadius: 20

public static CvSeq DetectCircles(IplImage pImage, CamEnum _camName)
{
    try
    {
        CvMemStorage memStorage = cvlib.CvCreateMemStorage(0);
        return cvlib.CvHoughCircles(ref pImage, memStorage.ptr, 3, 1, 32, 10, 10, 13, 20);
    }
    catch
    {
        throw;
    }
}

https://i.sstatic.net/pUqbh.png

Upvotes: 1

scap3y
scap3y

Reputation: 1198

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. :)

Upvotes: 2

Michael Burdinov
Michael Burdinov

Reputation: 4448

Are you sure you are providing radius and not diameter? Try wider range of radiuses (10-100 for example).

Using OpenCV to cheat in Zuma? :)

Upvotes: 2

Related Questions