OpenCV cover image with ellipse

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

I mean, cropping the original image with an ellipse. Is it possible?

I am trying to draw an ellipse, but the ellipse does not draw a complete one, so:

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 did some tests with cvSetImageROIto crop the image, but this method only works with cvRect.

Some idea?

+3
source share
2 answers

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 res I have an image showing an ROI with an ellipse, and the rest in black.

+4
source

Source: https://habr.com/ru/post/1796552/


All Articles