OpenCV中使用vector<Point> 可以组成多个点的形状,或者四个点的旋转矩形。
带角度的矩形可以通过这种方式拿到:
vector<Point> ployPoints{Point(x1,y1),Point(x2,y2),Point(x3,y3),Point(x4,y5)};
RotatedRect rotated_rect = minAreaRect(ployPoints);
python中是这样的,其中segmentation是这样的:[x1, y1, x2, y2, x3, y3, x4, y4] :
segmentation = segmentation.reshape([-1, 2])
rect1 = cv2.minAreaRect(segmentation)
x, y, w, h, theta = rect1[0][0], rect1[0][1], rect1[1][0], rect1[1][1], rect1[2]
发一下OpenCV-C++源码对RotatedRect的表述:
class CV_EXPORTS RotatedRect
{
public:
RotatedRect();
RotatedRect(const Point2f& center, const Size2f& size, float angle);
RotatedRect(const CvBox2D& box);
void points(Point2f pts[]) const;
Rect boundingRect() const;
operator CvBox2D() const;
Point2f center;
Size2f size;
float angle;
};
|