【opencv+VS】图片中找圆
来源:学生作业帮 编辑:大师作文网作业帮 分类:综合作业 时间:2024/11/12 13:02:55
【opencv+VS】图片中找圆
我采集一幅图片,jpf、png都行,然后转成YUV422格式,找图片中的圆,opencv怎么实现呢?
我采集一幅图片,jpf、png都行,然后转成YUV422格式,找图片中的圆,opencv怎么实现呢?
#include
#include
#include
int main(int argc, char** argv)
{
IplImage* if(img)
{
IplImage* gray = cvCreateImage(
cvGetSize(img), 8, 1 );
CvMemStorage* storage =
cvCreateMemStorage(0);
cvCvtColor( img, gray, CV_BGR2GRAY
);
cvSmooth( gray, gray, CV_GAUSSIAN,
9, 9 ); // smooth it, otherwise a lot of false circles //may be detected
CvSeq* circles = cvHoughCircles(
gray, storage, CV_HOUGH_GRADIENT, 2, gray->height/4, 200, 100 );
int i;
for( i = 0; i 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 );
}
cvNamedWindow( "circles",
1 );
cvShowImage( "circles",
cvWaitKey(0);
}
return 0;
}
这是未转换成yuv格式的,将输入的图像灰度化进行处理
如果想要转成yuv格式,调用cvCvtColor(img,yuv,CV_BGR2YUV);即可得到yuv格式图像,其中的y分量即为灰度图
#include
#include
int main(int argc, char** argv)
{
IplImage* if(img)
{
IplImage* gray = cvCreateImage(
cvGetSize(img), 8, 1 );
CvMemStorage* storage =
cvCreateMemStorage(0);
cvCvtColor( img, gray, CV_BGR2GRAY
);
cvSmooth( gray, gray, CV_GAUSSIAN,
9, 9 ); // smooth it, otherwise a lot of false circles //may be detected
CvSeq* circles = cvHoughCircles(
gray, storage, CV_HOUGH_GRADIENT, 2, gray->height/4, 200, 100 );
int i;
for( i = 0; i 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 );
}
cvNamedWindow( "circles",
1 );
cvShowImage( "circles",
cvWaitKey(0);
}
return 0;
}
这是未转换成yuv格式的,将输入的图像灰度化进行处理
如果想要转成yuv格式,调用cvCvtColor(img,yuv,CV_BGR2YUV);即可得到yuv格式图像,其中的y分量即为灰度图