How to find circles in an image
Hi in the below image how do you find and mark all the circles and identify the defect, my vs is vs2010 and opencv 2.4.10
this is my code so far, but it doesnt detect anything:
static void findCircles2(const Mat& image)
{
vector<Vec3f> circles;
int thresh1 = 5;
Mat pyr, timg, gray0(image.size(), CV_8U), gray;
pyrDown(image, pyr, Size(image.cols/2, image.rows/2));
pyrUp(pyr, timg, image.size());
for( int c = 0; c < 3; c++ )
{
int ch[] = {c, 0};
mixChannels(&timg, 1, &gray0, 1, ch, 1);
Canny(gray0, gray, 0, thresh1, 5);
//dilate(gray, gray, Mat(), Point(-1,-1));
gray = gray0 >= (1)*255/N;
gray = gray0 >= (2)*255/N;
gray = gray0 >= (6)*255/N;
namedWindow( "Hough Circle Transform Demo 1", CV_WINDOW_AUTOSIZE );
imshow( "Hough Circle Transform Demo 1", gray );
waitKey(0);
HoughCircles( gray, circles, CV_HOUGH_GRADIENT, 1, gray.rows/8, 200, 100, 0, 0 );
cout<<"size of circles: "<<circles.size()<<endl;
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( gray, center, 3, Scalar(0,255,0), -1, 8, 0 );
circle( gray, center, radius, Scalar(0,0,255), 3, 8, 0 );
}
/// Show your results
namedWindow( "Hough Circle Transform Demo 2", CV_WINDOW_AUTOSIZE );
imshow( "Hough Circle Transform Demo 2", gray );
waitKey(0);
}
}
I don't see duplicate.
@AdhilIqbal, please do NOT post duplicate questions about this, thank you.
@supra56, you don't see them, because they are already deleted
@berak. I thought you were, talking to me.
@supra56, apologies for the confusion, then
@AdhilIqbal Why do you expect help when you didn't even say thank you for the last time you got help? Are you a capitalist pig?
@sjhalayka , now, cmon ...
@sjhalayka sorry you had to resort to foul language, but thank you for pointing out that I hadn't said thank you. sometimes i myself forget the trouble you go through to answer these questions
Sorry for calling you a pig. You’re welcome.
@AdhilIqbal , btw, IF you want to use anything hough related, try to drop the Canny (it's doing it's own internally) .