简体   繁体   English

如何创建旋转的矩形或多边形ROI /蒙版?

[英]How to create rotated rectangular or polygonal ROI/mask?

Let's say i have the following image: 假设我有以下图片:

在此输入图像描述

And my region of interest looks like this: 我感兴趣的区域看起来像这样:

投资回报率

And i want to have the following result: 我希望得到以下结果:

在此输入图像描述

How can i achieve this knowing that the ROI is denoted by four points: 我怎样才能知道ROI由四点表示:

 Point pt1(129,9);
 Point pt2(284,108);
 Point pt3(223,205);
 Point pt4(67,106);

The idea is to use fillPoly() to fill all the pixels inside the rotated-rectangle/polygon to 0, 255 otherwise: 我们的想法是使用fillPoly()将旋转矩形/多边形内的所有像素填充为0,255,否则:

Mat mask = cv::Mat(img.size(), CV_8UC1, Scalar(255));     // suppose img is your image Mat

vector<vector<Point>> pts = { { pt1, pt2, pt3, pt4 } };
fillPoly(mask, pts, Scalar(0));                           // <- do it here

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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