class RotatedRect
The class represents rotated (i.e. notup-right) rectangles on a plane. Each rectangle is specified by the centerpoint (mass center), length of each side (represented by cv::Size2f structure)and the rotation angle in degrees.
C++: RotatedRect::RotatedRect()
C++: RotatedRect::RotatedRect(const Point2f& center, const Size2f& size, float angle)
C++: RotatedRect::RotatedRect(const CvBox2D& box)
Parameters
center – The rectangle masscenter.
size – Width and height of therectangle.
angle – The rotation angle in aclockwise direction. When the angle is 0, 90, 180,270 etc., the rectanglebecomes an up-right rectangle.
box – The rotated rectangle parametersas the obsolete CvBox2D structure.
C++: void RotatedRect::points(Point2f pts[]) const
C++: Rect RotatedRect::boundingRect() const
C++: RotatedRect::operator CvBox2D() const
Parameters
pts – The points array forstoring rectangle vertices.
Mat image(200, 200, CV_8UC3, Scalar(0));
RotatedRect rRect = RotatedRect(Point2f(100,100), Size2f(100,50), 30);
Point2f vertices[4];
rRect.points(vertices);
for (int i = 0; i < 4; i++)
line(image, vertices[i], vertices[(i+1)%4], Scalar(0,255,0));
Rect brect = rRect.boundingRect();
rectangle(image, brect, Scalar(255,0,0));
imshow("rectangles", image);

本文详细介绍了OpenCV中的RotatedRect类,包括构造函数、参数含义以及如何获取旋转矩形的顶点和边界框。通过对旋转矩形的中心点、尺寸和旋转角度的探讨,展示了如何在实际应用中操作和绘制有向边框。
1034





