您的位置:首页 > 运维架构

RotatedRect类opencv

2016-06-15 19:41 351 查看
RotatedRect该类表示平面上的旋转矩形,有三个属性:

矩形中心点(质心)
边长(长和宽)
旋转角度

class CV_EXPORTS RotatedRect
{
public:
//构造函数
RotatedRect();
RotatedRect(const Point2f& center, const Size2f& size, float angle);
RotatedRect(const CvBox2D& box);

//!返回矩形的4个顶点
void points(Point2f pts[]) const;
//返回包含旋转矩形的最小矩形
Rect boundingRect() const;
//!转换到旧式的cvbox2d结构
operator CvBox2D() const;

Point2f center; //矩形的质心
Size2f size;    //矩形的边长
float angle;    //旋转角度,当角度为0、90、180、270等时,矩形就成了一个直立的矩形
};
示例程序:
#include"iostream"
#include"opencv2/opencv.hpp"

using namespace std;
using namespace cv;

int main()
{
Mat image(200, 200, CV_8UC3, Scalar(0));
RotatedRect rRect(Point2f(100, 100), Size2f(100, 50), 30);

Point2f vertices[4];      //定义矩形的4个顶点
rRect.points(vertices);   //计算矩形的4个顶点
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);
waitKey(0);
}


运行结果:

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