OpenCV裁剪图像与椭圆 [英] OpenCV crop image with ellipse

查看:332
本文介绍了OpenCV裁剪图像与椭圆的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个大小为 92x112的图像(cv :: Mat)。我想用椭圆包围这个图像中的对象,然后只得到这个像素来创建另一个只包含对象的图片。



我的意思是,用椭圆裁剪原始图片。
这是可能吗?



我试图画一个椭圆,但是椭圆没有绘制完整,有:

 椭圆(escalada,Point(92 / 2,112 / 2),Size(92/2 * 0.95,112 / 2 * 0.85),0.0,90.0,0.0,Scalar (255,0,0),3,8); 

并使用 cvSetImageROI 图像,但此方法仅适用于 cvRect



一些想法?

解决方案

我用这个解决:

  imagen = imread nombre_imagen,0); // read image(grayscale)
//使用旧的C接口
IplImage * res,* roi;
IplImage src(imagen);
res = cvCreateImage(Size(imagen.rows,imagen.cols),8,1);
roi = cvCreateImage(Size(imagen.rows,imagen.cols),8,1);
cvZero(roi);
cvEllipse(roi,cvPoint(src.width / 2,src.height / 2),cvSize(src.width / 2 * 0.85,src.height / 2 * 0.95),0.0,0.0,360.0,CV_RGB 255,255,255), - 1,8,0);

cvAnd(& src,& src,res,roi);
cvReleaseImage(& roi);

然后在res变量我有一个图像显示投资回报率椭圆和其余的黑色。 / p>

I have an image (cv::Mat) with size of 92x112 I want to surround the object in this image with a ellipse then get only this pixels to create another image containing only the object.

I mean, cropping the original image with a ellipse. It's possible?

I am trying drawing a ellipse, but the ellipse don't draw complete, with that:

ellipse(escalada, Point(92/2,112/2), Size(92/2*0.95,112/2*0.85), 0.0, 90.0, 0.0, Scalar(255,0,0), 3, 8);

and made some test with cvSetImageROI to crop the image, but this method works only with cvRect.

Some idea?

解决方案

I solve using this:

imagen = imread(nombre_imagen,0); //read image (grayscale)
//Use old C interface 
IplImage *res,*roi;
IplImage src(imagen);
res = cvCreateImage(Size(imagen.rows,imagen.cols),8,1);
roi = cvCreateImage(Size(imagen.rows,imagen.cols),8,1);
cvZero(roi);
cvEllipse(roi,cvPoint(src.width/2,src.height/2),cvSize(src.width/2*0.85,src.height/2*0.95),0.0,0.0,360.0,CV_RGB(255,255,255),-1,8,0);

cvAnd(&src, &src, res, roi);
cvReleaseImage(&roi);

then in res variable i have a image showing the ROI with a ellipse and the rest in black.

这篇关于OpenCV裁剪图像与椭圆的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆