用OpenCV进行圆标志检测的vc代码
作者:cnfgg 日期:2010-08-16
IplImage* img=cvLoadImage("D:\\circles.jpg", 1);
IplImage* gray = cvCreateImage( cvGetSize(img), 8, 1 );
CvMemStorage* storage = cvCreateMemStorage(0);
cvCvtColor( img, gray, CV_BGR2GRAY );
//cvNormalize(gray, gray,255, 0, CV_MINMAX);
cvSmooth( gray, gray, CV_GAUSSIAN, 3, 3 ); // smooth it, otherwise a lot of false circles may be detected
IplConvKernel *element=0;
element=cvCreateStructuringElementEx(3,3,1,1,CV_SHAPE_ELLIPSE,0);
cvDilate(gray,gray,element,2);
cvErode(gray,gray,element,2);
cvReleaseStructuringElement(&element);
CvSeq* circles = cvHoughCircles( gray, storage, CV_HOUGH_GRADIENT, 2, 25, 300, 30 , 3, 35);
for( i = 0; i < circles->total; i++ )
{
float* p = (float*)cvGetSeqElem( circles, i );
cvCircle( img, cvPoint(cvRound(p[0]),cvRound(p[1])), 3, CV_RGB(0,255,0), -1, 8, 0 );
cvCircle( img, cvPoint(cvRound(p[0]),cvRound(p[1])), cvRound(p[2]), CV_RGB(255,0,0), 3, 8, 0 );
cout<<"圆心坐标x= "<<cvRound(p[0])<<endl<<"圆心坐标y= "<<cvRound(p[1])<<endl;
cout<<"半径="<<cvRound(p[2])<<endl;
}
cvRelease((void**)&img);
cvRelease((void**)&gray);
cvRelease((void**)&circles);
cvReleaseMemStorage(&storage);
评论: 0 | 引用: 0 | 查看次数: -
发表评论
上一篇
下一篇

文章来自:
Tags:
相关日志: