Ask Your Question

Revision history [back]

Hi.

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

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);

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;

}

Hi.

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

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

1);
    Mat gray;

 cvtColor(img, gray, CV_RGB2GRAY);

 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;


}

}

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;


}