OpencvRotatedRect类中的points、angle、width、height等详解

更新时间:2023-05-11 06:07:45 阅读: 评论:0

OpencvRotatedRect类中的points、angle、width、height等详
在OpenCV中,经常要⽤到minAreaRect()函数求最⼩外接矩形(旋转矩形)。该函数返回⼀个RotatedRect类对象。
RotatedRect类定义如下:
class CV_EXPORTS RotatedRect
{
public:
//! various constructors
RotatedRect();
RotatedRect(const Point2f& center, const Size2f& size, float angle);
RotatedRect(const CvBox2D& box);
//! returns 4 vertices of the rectangle
void points(Point2f pts[]) const;
//! returns the minimal up-right rectangle containing the rotated rectangle
Rect boundingRect() const;
//! conversion to the old-style CvBox2D structure
operator CvBox2D() const;
Point2f center; //< the rectangle mass center
Size2f size;    //< width and height of the rectangle
float angle;    //< the rotation angle. When the angle is 0, 90, 180, 270 etc., the rectangle becomes an up-right rectangle.
};
类中有中⼼点center、尺⼨size(包括width、height)、旋转⾓度angle共3个成员变量;
成员函数中,points()函数求矩形的4个顶点;boundingRect()函数求包含最⼩外接矩形,与坐标轴平⾏(或垂直)的最⼩矩形。
理解这些变量在图形中的对应关系,是正确应⽤该类的基础。先上⽰意图:
根据上图,说明以下⼏点:
1.  Opencv采⽤通⽤的图像坐标系,左上⾓为原点O(0,0),X轴向右递增,Y轴向下递增,单位为像素。
2. 矩形4个顶点位置的确定,是理解其它各变量的基础,其中p[0]点是关键。
顶点p[0]的位置可以这样理解:
如果没有边与坐标轴平⾏,则Y坐标最⼤的点为p[0]点,如矩形(2)(3)(4);
如果有边与坐标轴平⾏,则有两个Y坐标最⼤的点。此时,左侧的点为p[0]点。如矩形(1)。
即:Y坐标最⼤的点为p[0]。如果有两个最⼤的Y坐标,则左侧点(X坐标较⼩)为p[0]。
3. p[0]~p[3]按顺时针⽅向依次排列。
4. p[0]到p[3]之间的距离为宽width,其邻边为⾼height。
5. ⾓度angle,是以p[0]顶点,平⾏于X轴,且与X轴⽅向相同的射线为始边,按逆时针⽅向旋转到宽边p[0]p[3]所经过的⾓度,    取负值,取值范围为(-90, 0]。
6. 中⼼点center为矩形对⾓线的交点。

本文发布于:2023-05-11 06:07:45,感谢您对本站的认可!

本文链接:https://www.wtabcd.cn/fanwen/fan/89/881949.html

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

标签:矩形   递增   函数
相关文章
留言与评论(共有 0 条评论)
   
验证码:
推荐文章
排行榜
Copyright ©2019-2022 Comsenz Inc.Powered by © 专利检索| 网站地图