Mark Freewind
Mark Freewind

Reputation: 13

Crop an ellipse form from an image instead of drawing it inside in OpenCV

I have a rectangle that I want to extract the ellipse form of it from a given image. My code looks like:

RotatedRect ellipse ;
float p1 = (float) rect.width/2 + rect.x;
float p2 = (float) rect.height/2 + rect.y;
CvPoint2D32f p = cvPoint2D32f(p1,p2);
ellipse.center = p;
ellipse.angle = 0;
ellipse.size =  cvSize2D32f((float)rect.width, (float)rect.height);
ellipse( image_colored, minEllipse, CV_RGB(255,255,255), 2, 8 );

The input of this code are: an image (image_colored) and CvRect (rect). The last line of code, draws a white ellipse inside the "image_colored", but I am looking to crop the generated ellipse in an other image or just color the rest of the image in black.

Any help, will be highly appreciated. Thank you.

PS: I can not use the function cvEllipse(...) as it was suggested in this link. Because cvEllipse does not accept an object of type CvPoint2D32f, neither CvSize2D32f type.

Upvotes: 0

Views: 1935

Answers (1)

Martin Beckett
Martin Beckett

Reputation: 96109

Make an image with a filled ellipse and use this as a mask combined (bitwise and) with your image OpenCV bitwise_and + mask or Segmenting Lungs and nodules in CT images

Upvotes: 2

Related Questions