Ask Your Question

Revision history [back]

Hough Transform failed!

image description

This is a picture above. I am using opencv to process it and I have tried to use Hough Transform, but failed. Also, I found that it is so hard to set relative parameters in Hough Transform.

The codes are as following:

#include <opencv2/opencv.hpp>

using namespace cv;
using namespace std;

int main()
{
    Mat srcImg = imread("srccenter.bmp");
    Mat greyImg;
    cvtColor(srcImg, greyImg, COLOR_BGR2GRAY);

    std::vector<cv::Vec3f> circles;

    /// Apply the Hough Transform to find the circles
    HoughCircles(greyImg, circles, CV_HOUGH_GRADIENT, 1, 10, 100, 20, 0, 0);

    /// Draw the circles detected
    for (size_t i = 0; i < circles.size(); i++)
    {
        Point center(cvRound(circles[i][0]), cvRound(circles[i][1]));
        int radius = cvRound(circles[i][2]);
        circle(srcImg, center, 3, Scalar(0, 255, 255), -1);
        circle(srcImg, center, radius, Scalar(0, 255, 0), 1);
    }

    namedWindow("srcImg", WINDOW_NORMAL);
    imshow("srcImg", srcImg);
    waitKey(0);
    return 0;
 }

But the result is I can not detect any circle.

How I can detect the inner circle?

Do you have any good ideas?