Hough Transform failed!
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?
it seems, like you forget the picture you are using?
Maybe not, I changed the relative parameters, and find some circles. But I don't think I learn the meaning of these parameters deeply.
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 );
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!
Why need GaussianBlur?
@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 TutorialOk, 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.
Did you test it again now? How is the output? As expected?