目录
#include<opencv2\opencv.hpp>
using namespace std;
using namespace cv;
void main()
{
cv::RotatedRect box = RotatedRect(Point2f(220, 250), Size2f(100, 200), 30);
Point2f rect[4];
box.points(rect);
cv::Point2f center = box.center;
vector<cv::Point2f> expand_sets;
for (int i = 0; i < 4; i++)
{
float distance = sqrt((rect[i].x - center.x)*(rect[i].x - center.x) + (rect[i].y - center.y)*(rect[i].y - center.y));
float scale = 1 + 20 / distance;
expand_sets.push_back((rect[i] - center) *scale + center);
}
cv::Mat img = cv::Mat::zeros(480, 600, CV_8UC3);
Point2f rect1[4];
box.points(rect1);
for (int i = 0; i < 4; i++)
{
line(img, rect1[i], rect1[(i + 1) % 4], Scalar(255, 255, 255), 2);
line(img, expand_sets[i], expand_sets[(i + 1) % 4], Scalar(0, 255, 255), 2);
}
imshow("可视化", img);
waitKey(0);
}
![在这里插入图片描述](https://img-blog.csdnimg.cn/4fa3a929f86546249abc10d02a312942.png#pic_center)