我正在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.)它没有多次输入:(
期待指导......