您的位置:首页 > 其它

RotatedRect类(旋转矩形)

2015-11-18 10:55 316 查看
C++: RotatedRect::RotatedRect(const
Point2f& center, const Size2f& size,
float angle)

Parameters:center – The rectangle mass center.
size – Width and height of the rectangle.
angle – The rotation angle in a clockwise direction. When the angle is 0, 90, 180, 270 etc., the rectangle becomes an up-right rectangle.

C++: void RotatedRect::points(Point2f pts[]) const

Parameters:pts – The points array for storing rectangle vertices.

C++: Rect boundingRect(InputArray points)

Parameters:points – Input 2D point set, stored in std::vector or Mat.
The function calculates and returns the minimal up-right bounding rectangle for the specified point set.

示例如下:

#include <opencv2/opencv.hpp>

#include <iostream>

using namespace std;

using namespace cv;

int main()

{

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(255,255,255));//白色矩形

Rect brect = rRect.boundingRect();

rectangle(image, brect, Scalar(255,0,0));

imshow("rectangles", image);

waitKey();

return 0;

}



内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: