我在 openCV 2.1 和 Visual Studio 2008 中编译以下代码,
int main()
{
Mat src, src_gray;
/// Read the image
src = cvLoadImageM("Circle_3.jpg",1);
if( !src.data )
{
cout<<" "<<"Error!!!!!!!!!!"<<endl;
return -1;
}
/// Convert it to gray
cvtColor( src, src_gray, CV_BGR2GRAY );
/// Reduce the noise so we avoid false circle detection
GaussianBlur( src_gray, src_gray, Size(9, 9), 2, 2 );
vector<Vec3f> circles;
/// Apply the Hough Transform to find the circles
HoughCircles( src_gray, circles, CV_HOUGH_GRADIENT, 1, src_gray.rows/8, 200, 100, 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 center
circle( src, center, 3, Scalar(0,255,0), 3, 8, 0 );
// circle outline
circle( src, center, radius, Scalar(0,0,255), 3, 8, 0 );
}
/// Show your results
imshow( "Hough Circle Transform Demo", src );
waitKey(0);
return 0;
}
这段代码有两个问题:1.)它没有给出想要的结果(构建得很好!)2.)它没有多次输入:(
期待指导...