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:
//! various constructors
RotatedRect();
RotatedRect(const Point2f& center, const Size2f& size, float angle);
RotatedRect(const CvBox2D& box);
//! returns 4 vertices of the rectangle
void points(Point2f pts[]) const;
//! returns the minimal up-right rectangle containing the rotated rectangle
Rect boundingRect() const;
//! conversion to the old-style CvBox2D structure
operator CvBox2D() const;
Point2f center; //< the rectangle mass center
Size2f size; //< width and height of the rectangle
float angle; //< the rotation angle. When the angle is 0, 90, 180, 270 etc., the rectangle becomes an up-right rectangle.
};
轉載請註明出處,本文鏈接:https://www.uj5u.com/qita/295508.html
標籤:其他
下一篇:OpenCV-Python教程:形態學變換~開閉操作,頂帽黑帽,形態學梯度,擊中擊不中(morphologyEx)
