关闭

RotatedRect类(旋转矩形)

786人阅读 评论(0) 收藏 举报
分类:

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;
}



0
0

查看评论
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
    个人资料
    • 访问:104345次
    • 积分:3914
    • 等级:
    • 排名:第8064名
    • 原创:288篇
    • 转载:0篇
    • 译文:13篇
    • 评论:19条
    最新评论