我想要在opencv中用最小矩形外接图中图像并剪切截取出这个矩形部分。
发布网友
发布时间:2022-05-02 10:34
我来回答
共2个回答
热心网友
时间:2023-10-03 04:26
试试 里面一些参数要改一下 这是c++
vector<vector<Point>> vecContour;
vector<Vec4i> hierarcy;
findContours(dst1, vecContour, CV_RETR_LIST, CV_CHAIN_APPROX_SIMPLE);//查找轮廓
Rect boundRect;//存放外接矩形
RotatedRect rorect;//存放最小外接矩形
Point2f rect[4];
//vector<vector<Point>>proRect;
//Mat imageContours = Mat::zeros(image.size(), CV_8UC1);
for (int i = 0; i < vecContour.size(); i++)
{
boundRect = boundingRect(Mat(vecContour[i]));
if (boundRect.width < 200 || boundRect.height < 200)
continue;
circle(dst1, Point(rorect.center.x, rorect.center.y), 5, Scalar(0, 255, 0), -1, 8); //绘制最小外接矩形的中心点
rorect.points(rect); //把最小外接矩形四个端点复制给rect数组
rectangle(dst1, Point(boundRect.x, boundRect.y), Point(boundRect.x + boundRect.width, boundRect.y + boundRect.height), Scalar(0, 255, 0), 2, 8);
for (int j = 0; j < 4; j++)
{
line(dst1, rect[j], rect[(j + 1) % 4], Scalar(255, 0, 0), 2, 8); //绘制最小外接矩形每条边
}
}
热心网友
时间:2023-10-03 04:27
用弹簧测力计测量出物体的重力G
热心网友
时间:2023-10-03 04:26
试试 里面一些参数要改一下 这是c++
vector<vector<Point>> vecContour;
vector<Vec4i> hierarcy;
findContours(dst1, vecContour, CV_RETR_LIST, CV_CHAIN_APPROX_SIMPLE);//查找轮廓
Rect boundRect;//存放外接矩形
RotatedRect rorect;//存放最小外接矩形
Point2f rect[4];
//vector<vector<Point>>proRect;
//Mat imageContours = Mat::zeros(image.size(), CV_8UC1);
for (int i = 0; i < vecContour.size(); i++)
{
boundRect = boundingRect(Mat(vecContour[i]));
if (boundRect.width < 200 || boundRect.height < 200)
continue;
circle(dst1, Point(rorect.center.x, rorect.center.y), 5, Scalar(0, 255, 0), -1, 8); //绘制最小外接矩形的中心点
rorect.points(rect); //把最小外接矩形四个端点复制给rect数组
rectangle(dst1, Point(boundRect.x, boundRect.y), Point(boundRect.x + boundRect.width, boundRect.y + boundRect.height), Scalar(0, 255, 0), 2, 8);
for (int j = 0; j < 4; j++)
{
line(dst1, rect[j], rect[(j + 1) % 4], Scalar(255, 0, 0), 2, 8); //绘制最小外接矩形每条边
}
}
热心网友
时间:2023-10-03 04:27
用弹簧测力计测量出物体的重力G