opencv rotatedrect 获取顶点

阅读: 评论:0

opencv rotatedrect 获取顶点

opencv rotatedrect 获取顶点

 

OpenCV对图片中的RotatedRect进行填充

 

class CV_EXPORTS RotatedRect
{
public://构造函数RotatedRect();RotatedRect(const Point2f& center, const Size2f& size, float angle);RotatedRect(const CvBox2D& box);void points(Point2f pts[]) const;//!返回矩形的4个顶点Rect boundingRect() const; //返回包含旋转矩形的最小矩形operator CvBox2D() const;    //!转换到旧式的cvbox2d结构Point2f center; //矩形的质心Size2f size;   //矩形的边长float angle;  //旋转角度,当角度为0、90、180、270等时,矩形就成了一个直立的矩形
};
#include<opencv2/opencv.hpp>
#include<iostream>
using namespace std;
using namespace cv;int main()
{Mat img = imread("C:/1.jpg");Mat img_gray;cvtColor(img, img_gray, COLOR_RGB2GRAY);img_gray = img_gray > 30;vector<vector<Point>>contours;vector<Vec4i> hierarchy;vector<RotatedRect>rect;//【5】查找轮廓findContours(img_gray, contours, RETR_EXTERNAL, CHAIN_APPROX_SIMPLE);for (int i = 0; i < contours.size(); i++){rect.push_back(minAreaRect(contours[i]));Point2f vertices[4];      //定义矩形的4个顶点rect[i].points(vertices);   //计算矩形的4个顶点for (int i = 0; i < 4; i++)line(img, vertices[i], vertices[(i + 1) % 4], Scalar(0, 255, 0),1);cout <<"width的值:"<<rect[i].size.width << endl;cout << "height的值:" << rect[i].size.height << endl;//其实只有一个外接矩形}imshow("img", img);waitKey(0); }
}

 

 

 

 

Reference

2 .html

 

 

 

 

 

 

本文发布于:2024-02-04 15:50:44,感谢您对本站的认可!

本文链接:https://www.4u4v.net/it/170710946156833.html

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。

标签:顶点   opencv   rotatedrect
留言与评论(共有 0 条评论)
   
验证码:

Copyright ©2019-2022 Comsenz Inc.Powered by ©

网站地图1 网站地图2 网站地图3 网站地图4 网站地图5 网站地图6 网站地图7 网站地图8 网站地图9 网站地图10 网站地图11 网站地图12 网站地图13 网站地图14 网站地图15 网站地图16 网站地图17 网站地图18 网站地图19 网站地图20 网站地图21 网站地图22/a> 网站地图23