Ask Your Question
0

HoughCircle fail to detect the circular part.

asked 2013-04-22 15:14:28 -0600

hayden gravatar image

Hello every body, I have placed an image to the following link:

http://i35.tinypic.com/16kozua.png

I used the following code to detect the interior circle, but it does not show any circular region. Could any one explain?

include <cv.h>

include <highgui.h>

include <math.h>

using namespace cv; int main(int argc, char** argv) { Mat img, gray; if( argc != 2 && !(img=imread(argv[1], 1)).data) return -1;

img=imread(argv[1], 1);

cvtColor(img, gray, CV_BGR2GRAY);

// smooth it, otherwise a lot of false circles may be detected

GaussianBlur( gray, gray, Size(9, 9), 2, 2 );
vector<Vec3f> circles;

HoughCircles(gray, circles, CV_HOUGH_GRADIENT, 2, gray.rows/4, 200, 100 );
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]);
     // draw the circle center
     circle( img, center, 3, Scalar(0,255,0), -1, 8, 0 );
     // draw the circle outline
     circle( img, center, radius, Scalar(0,0,255), 3, 8, 0 );
}
namedWindow( "circles", 1 );
imshow( "circles", img );
 cvWaitKey();
return 0;

}

edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted
0

answered 2013-04-22 23:39:58 -0600

NightLife gravatar image

updated 2013-04-22 23:40:37 -0600

Your code seems normal and I think the problem is the input image. Have you tried other images?

edit flag offensive delete link more

Comments

I have tried with other similar images, but the result is same. Do i need to use some filtering for this? Would you recommend any filter?

hayden gravatar imagehayden ( 2013-04-23 14:40:42 -0600 )edit

Right now, the thing that I can suggest you is using medianBlur() , but I do not know that it is usefull or not.

NightLife gravatar imageNightLife ( 2013-04-23 23:35:02 -0600 )edit

Question Tools

Stats

Asked: 2013-04-22 15:14:28 -0600

Seen: 289 times

Last updated: Apr 22 '13