简体   繁体   中英

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.

使用填充的椭圆制作图像并将其用作与图像组合(按位和)的掩码OpenCV bitwise_and + maskCT图像中的分段肺和结节

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM