OpenCV中基本数据结构(5)_RotatedRect

RotatedRect也是表示一个矩形框,但是与Rect不同的是,RotatedRect可以带倾斜角的矩形,如下图所示:

 RotatedRect结构中包括三个变量:

 Point2f center:为矩形的中心点位置

Size2f size:矩形框width和height

float angle:为左上角与X轴夹角。与X轴的平行方向角度为0,逆时针旋转角度为负,顺时针旋转角度为正。当角度为0, 90, 180, 270,则和Rect一样

RotatedRect与其他数据结构不一样,数据类型都是固定的,没有其他数据类型。

Learning OpenCV3中指出了RotatedRect与Rect一个重要不同:

One very important difference between cv::RotatedRect and cv::Rect is the convention that a cv::RotatedRect is located in "space" relative to its center, while the cv::Rect is located relative to its upper-left corner.

RotatedRect类

RotatedRect类定义如下:

 使用总结如下:

MedthodDescription
RotatedRect()默认构造函数
 RotatedRect(const Point2f& center, const Size2f& size, float angle)

带参数构造函数:

center:为矩形中心位置

size:为矩形宽度和高度

angle:为与x轴夹角

RotatedRect(const Point2f& point1, const Point2f& point2, const Point2f& point3)

带参数构造函数:

根据矩形框的三个点确定一个RotatedRect

point1、point2、point3矩形三个点

void points(Point2f pts[]) 返回矩阵的四个角点的左边,顺序为:bottomLeft, topLeft, topRight, bottomRight.
Rect boundingRect() 返回能够包含旋转矩形框的最小矩形,返回的是Rect没有带角度
Rect_<float> boundingRect2f() 返回能够包含旋转矩形框的最小矩形,返回的是Rect没有带角度,其数据类型为float
Point2f center矩形中心点位置
Size2f size矩形的宽度和高度
float angle矩形夹角

 来自于opencv官网的RotatedRect用例:https://docs.opencv.org/3.2.0/db/dd6/classcv_1_1RotatedRect.html#ae1be388780b8d5faf450be18cbbf30f1

#include <stdio.h>
#include "opencv2/opencv.hpp"

using namespace cv;

void 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(0, 255, 0));
	Rect brect = rRect.boundingRect();
	rectangle(image, brect, Scalar(255, 0, 0));
	imshow("rectangles", image);
	waitKey(0);

}

运行结果:

 RotatedRect没有对operator进行重构,不支持+,-,*,/以及&,|等操作符

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Huo的藏经阁

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值