Ask Your Question
0

Houghcircles not acting properly

asked 2017-06-01 16:57:08 -0600

unxnut gravatar image

I have an application where I need to look at multiple [almost] concentric circles. I have been having issues using HoughCircles and so, I decided to create a test image with a single circle. My image was created with the following command:

cv::Mat img = cv::Mat::zeros ( 480, 640, CV_8UC1 );
cv::circle ( img, cv::Point(200,200), 175, cv::Scalar(0XFF), 1);

I tried to run HoughCircles on this image as follows:

std::vector<cv::Vec3f> circles;
cv::HoughCircles(img, circles, cv::HOUGH_GRADIENT, 1, 10, 239, 20 );

I get a plethora of circles when there is clearly only one circle in the input image. I have been struggling with this for a while now and will appreciate any help. I should mention that these circles are off-center from where I created the center (200,200), and their radius is all over the place as well.

edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted
0

answered 2017-06-02 04:29:35 -0600

alexcerry gravatar image

updated 2017-06-02 04:45:37 -0600

Hi.

edit1:

I try to get correct result. But its take time to adjust the correct parameter by the way you can check this out.

edit2:

Now i think result almost correct. after using canny and gaussian blur.

    int main()
    {
        cv::Mat img = cv::Mat::zeros(480, 640, CV_8UC3);
        cv::circle(img, cv::Point(200, 200), 175, cv::Scalar(0XFF), 1);
    Mat gray;

    cvtColor(img, gray, CV_RGB2GRAY);

Canny(gray, gray, 0, 10);

GaussianBlur(gray, gray, Size(9, 9), 2, 2);
    std::vector<cv::Vec3f> circles;

    bool exit = false;

    Point global;

    for (int i = 1; i < 200; i++)
    {
        HoughCircles(gray, circles, CV_HOUGH_GRADIENT,1, 20,200, i);
        cout << i << endl;

        for (size_t j = 0; j < circles.size(); j++)
        {
            Point center(cvRound(circles[j][0]), cvRound(circles[j][1]));
            int rad = circles[j][2];
            if (center.x > 199 && center.x < 201 && circles.size() < 45 && rad > 174)
            {
                global = center;
                exit = true;
            }
        }
        if (exit == true)
        {
            break;
        }
    }


    if (global.x > 0)
    {
    // circle center
    circle(img, global, 3, Scalar(0, 255, 0), 5, 8, 0);
    // circle outline
    circle(img, global, 175, Scalar(0, 0, 255), 3, 8, 0);

    }

    imshow("jk", img);
    waitKey(0);

    return 0;


}
edit flag offensive delete link more

Question Tools

1 follower

Stats

Asked: 2017-06-01 16:57:08 -0600

Seen: 749 times

Last updated: Jun 02 '17