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

How to create rotated rectangular or polygonal ROI/mask?

假设我有以下图像:

我感兴趣的区域是这样的:

我想得到以下结果:

知道投资回报率由四点表示,我如何实现这一目标:

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

思路是用fillPoly()把rotated-rectangle/polygon里面的所有像素都填成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