OpenCV完成下图中圆形图像(靠近外圆无突出部分的圆形)的检测
作者:互联网
#include "stdafx.h"
#include "highgui.h"
#include "cv.h"
#include "cxcore.h"
#include "math.h"
int main(int argc, char* argv[])
{
IplImage* image0=cvLoadImage("D:\\OOTT\\捕获.png",CV_LOAD_IMAGE_GRAYSCALE);
IplImage *image1=cvLoadImage("D:\\OOTT\\捕获.png",1);
CvMemStorage* storage=cvCreateMemStorage(0);
cvSmooth(image0,image0,CV_GAUSSIAN,5,5);
CvSeq* results=cvHoughCircles(image0,storage,CV_HOUGH_GRADIENT,2,image0->width /10);
int j = 0;
int max = 0;
for(int i=0;i<results->total ;i++)
{
float* p=(float*) cvGetSeqElem(results,i);
// CvPoint pt=cvPoint(cvRound(p[0]),cvRound(p[1]));
if(cvRound(p[2])>max)
{
max = cvRound(p[2]);
j = i;
}
}
float* p=(float*) cvGetSeqElem(results,j);
CvPoint pt=cvPoint(cvRound(p[0]),cvRound(p[1]));
cvCircle(image1,pt,cvRound(p[2]),CV_RGB(255,0,0));
cvNamedWindow("source",CV_WINDOW_AUTOSIZE);
cvShowImage("source",image0);
cvNamedWindow("cvHoughCircles",CV_WINDOW_AUTOSIZE);
cvShowImage("cvHoughCircles",image1);
cvWaitKey(0);
return 0;
}
结果如下图所示:
标签:include,外圆,cvRound,int,float,OpenCV,圆形,image0,CV 来源: https://blog.csdn.net/qq_30460949/article/details/89485363