3

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?

Soner Gönül
  • 97,193
  • 102
  • 206
  • 364
matiasfha
  • 1,270
  • 4
  • 23
  • 42

2 Answers2

4

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.

matiasfha
  • 1,270
  • 4
  • 23
  • 42
  • Is filter2D and cvZero the same thing? Cause in c++ Mat object we cant use cvAnd. – Sohaib Oct 07 '13 at 15:22
  • cvZero clears the array (the actual documentation of OpenCV use cvSetZero) filter2D: Convolves an image with the kernel. – matiasfha Oct 07 '13 at 16:09
  • Sorry I meant cvAnd and filter2D. I have found my answer there is bitwise_and in openCV for c++ API. – Sohaib Oct 07 '13 at 16:13
3

There is no direct support for non-rectangular ROI.
But you can use a mask - see http://docs.opencv.org/doc/tutorials/core/mat-mask-operations/mat-mask-operations.html (not directly circular but original tutorial doesn't exist)

Martin Beckett
  • 94,801
  • 28
  • 188
  • 263