在不同角度拍的照片可能是圆或者椭圆,现在我只能检测到圆,椭圆怎么检测??能在一张图里面同时检测圆和椭圆吗??我在论坛、贴吧找了很久,程序总是出错,有的达不到我想要的结果!!!所有有大神可以帮我一下吗??附上您的程序~~~~太感谢了~~下面是我检测圆的程序以及结果!!!请大神帮我在一张图片里可以同时检测圆和椭圆!!没办法附图D://save.jpg
#include<highgui.h> #include<cv.h> #include<opencv2/imgproc/imgproc.hpp> #include<math.h> using namespace cv; using namespace std; int main(int argc,char**argv) { IplImage*image=cvLoadImage("D://save.jpg",CV_LOAD_IMAGE_GRAYSCALE); CvMemStorage*storage=cvCreateMemStorage(0); cvSmooth(image,image,CV_GAUSSIAN,5,5); CvSeq*results=cvHoughCircles(image,storage,CV_HOUGH_GRADIENT,2,image->width/10); //依次在图中绘制出圆 for(inti=0;i<results->total;i++) { float*p=(float*) cvGetSeqElem(results,i); CvPointpt=cvPoint(cvRound(p[0]),cvRound(p[1])); cvCircle( image,pt, 2,Scalar(0,255,0), -1, 8, 0 ); cvCircle(image,pt,cvRound(p[2]), Scalar(0,0,255), 2, 8, 0 ); //cvCircle(image,pt,cvRound(p[2]),CV_RGB(0xff,0xff,0xff)); //在控制台输出圆心坐标和半径 cout<<" \n圆心x "<<cvRound(p[0])<<" \n圆心y "<<cvRound(p[1])<<" \n半径 "<<cvRound(p[2]); } //显示效果图 cvNamedWindow("效果图",0); cvShowImage("效果图",image); waitKey(0); }
|