Reputation: 147
I came across HoughCircles in OpenCV for circle detection. But it has a parameter which specifies minimum distance between detected circles. My concern is will that work in case two circles are concentric i.e. one circle within another?
Thanks Shashank
Upvotes: 3
Views: 2686
Reputation: 206
Another solution I've used in the past was to call the cv2.HoughCircles
function in a loop, but replace the area of the circle found with the color of a nearby pixel.
I understand this is not always possible, but it depends on the application.
Upvotes: 0
Reputation: 2263
Hough transform will only return 2 circles as two different objects if their centers are far enough apart (fifth parameter of Hough
).
So I think it's not possible to detect concentric circles that way (since their centers will be the same, or very close by).
The only way I see how to do it with Hough transform is to have an idea of the radius of the circles you're looking for, and call Hough
in a loop with varying min and max radius (last and next to last parameters of Hough
), each radius iteration corresponding to one of your concentric circles.
Upvotes: 3
Reputation: 463
I also think the OpenCv HougCircles detect only one radius per center. If you want to detect more radii, you will have to specify a smaller min distance between centers. But then those are not concentric circles. In short, I think openCv HoughCircle module is not designed to cater for concentric circles.
Upvotes: 1
Reputation: 1456
I tried with the shown image
But it is detecting only one circle...here is the code
Mat image_ = imread("E:/Work_DataBase/circle.jpg",3);
Mat image_temp;
cvtColor( image_, image_temp, CV_BGR2GRAY );
vector<Vec3f> circles;
HoughCircles( image_temp, circles, CV_HOUGH_GRADIENT, 1, image_temp.rows/8,100, 100, 10, 200 );
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 center
circle( image_, center, 3, Scalar(0,255,0), -1, 8, 0 );
// circle outline
circle( image_, center, radius, Scalar(0,0,255), 3, 8, 0 );
}
imshow("circles",image_);
waitKey(0);
I will try other options once if i find any alternative i will update you.
Upvotes: 1