#include<iostream>
#include<vector>
#include<opencv2/opencv.hpp>
using namespace cv;
using namespace std;
int main()
{
Mat srcImage(Size(600, 600), CV_8UC3, Scalar(0));
RNG &rng = theRNG();
char key;
while (1)
{
//随机生成一些点
//首先就是随机生成点的总数量
int g_nPointCount = rng.uniform(3, 200);
//接下来就是随机生成一些点的坐标
vector<Point> points;
for (int i = 0; i < g_nPointCount; i++)
{
Point midPoint;
midPoint.x = rng.uniform(srcImage.cols / 4, srcImage.cols * 3 / 4);
midPoint.y = rng.uniform(srcImage.rows / 4, srcImage.rows * 3 / 4);
points.push_back(midPoint);
}
//显示刚刚随机生成的那些点
for (int i = 0; i < g_nPointCount; i++)
{
circle(srcImage, points[i], 0, Scalar(rng.uniform(0, 255), rng.uniform(0, 255), rng.uniform(0, 255)), 3);
}
//在生成的那些随机点中寻找最小包围矩形
//rectPoint变量中得到了矩形的四个顶点坐标
RotatedRect rectPoint = minAreaRect(points);
//定义一个存储以上四个点的坐标的变量
Point2f
opencv3寻找最小包围矩形-minAreaRect函数
最新推荐文章于 2024-07-04 06:00:00 发布
![](https://img-home.csdnimg.cn/images/20240711042549.png)