Hough Transform failed!

asked 2016-11-30 23:01:04 -0500

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?

edit retag flag offensive close merge delete

Comments

it seems, like you forget the picture you are using?

Vintez gravatar imageVintez ( 2016-12-01 02:52:21 -0500 )edit

Maybe not, I changed the relative parameters, and find some circles. But I don't think I learn the meaning of these parameters deeply.

little tooth gravatar imagelittle tooth ( 2016-12-01 02:56:58 -0500 )edit

Sorry I have not made clear what I was meaning. In the beginning of the Question you say:

"This is a picture above. I am using opencv to process it and I have tried to use Hough Transform, but failed. "

I understand, that you wanted to show the picture you are processing with, or did I understand that wrong? ;D

Also you forgot the GaussianBlur didn't you? just after you converted it add GaussianBlur( greyImg, greyImg, Size(9, 9), 2, 2 );

Vintez gravatar imageVintez ( 2016-12-01 03:22:21 -0500 )edit

The reason I say: "This is a picture above.“ is I indeed have put up a picture on this web pages. And I am also curious why I can't see it. My problem is I can't detect circles on this picture through Hough Transform!

little tooth gravatar imagelittle tooth ( 2016-12-01 03:27:16 -0500 )edit

Why need GaussianBlur?

little tooth gravatar imagelittle tooth ( 2016-12-01 03:28:29 -0500 )edit
1

@little tooth the documentation or example of the Hough Transform says Apply a Gaussian blur to reduce noise and avoid false circle detection: Also in the example there are different parameters for the HoughCircle Method: HoughCircles( src_gray, circles, CV_HOUGH_GRADIENT, 1, src_gray.rows/8, 200, 100, 0, 0 ); Here the link to the Tutorial

Vintez gravatar imageVintez ( 2016-12-01 03:44:42 -0500 )edit

Ok, many thanks to you advice about GaussianBlur and relative parameters' setting. I get a primary conclusion that we have to choose these parameters in a proper range according to specific picture.

little tooth gravatar imagelittle tooth ( 2016-12-01 04:46:17 -0500 )edit

Did you test it again now? How is the output? As expected?

Vintez gravatar imageVintez ( 2016-12-01 04:47:26 -0500 )edit
1

Yes, I finally detected specific circle through changing some parameters in the function "HoughCircles", such as minDist, param1, param2, minRadius and maxRadius.

little tooth gravatar imagelittle tooth ( 2016-12-01 04:51:19 -0500 )edit