RotatedRect类opencv
2016-06-15 19:41
351 查看
RotatedRect该类表示平面上的旋转矩形,有三个属性:
矩形中心点(质心)
边长(长和宽)
旋转角度
运行结果:
矩形中心点(质心)
边长(长和宽)
旋转角度
class CV_EXPORTS RotatedRect { public: //构造函数 RotatedRect(); RotatedRect(const Point2f& center, const Size2f& size, float angle); RotatedRect(const CvBox2D& box); //!返回矩形的4个顶点 void points(Point2f pts[]) const; //返回包含旋转矩形的最小矩形 Rect boundingRect() const; //!转换到旧式的cvbox2d结构 operator CvBox2D() const; Point2f center; //矩形的质心 Size2f size; //矩形的边长 float angle; //旋转角度,当角度为0、90、180、270等时,矩形就成了一个直立的矩形 };示例程序:
#include"iostream" #include"opencv2/opencv.hpp" using namespace std; using namespace cv; int main() { Mat image(200, 200, CV_8UC3, Scalar(0)); RotatedRect rRect(Point2f(100, 100), Size2f(100, 50), 30); Point2f vertices[4]; //定义矩形的4个顶点 rRect.points(vertices); //计算矩形的4个顶点 for (int i = 0; i < 4; i++) line(image, vertices[i], vertices[(i + 1) % 4], Scalar(0, 255, 0)); Rect brect = rRect.boundingRect(); //返回包含旋转矩形的最小矩形 rectangle(image, brect, Scalar(255, 0, 0)); imshow("rectangles", image); waitKey(0); }
运行结果:
相关文章推荐
- OpenGL坐标转换总结
- Jenkins执行gradle任务提示Can't load log handler "4host-manager.org.apache.juli.FileHandler"
- APACHE默认模块功能说明
- 如何把一张照片用 Photoshop 做成动画背景效果?
- how to access and operate a binarry file ?
- Linux下使用libreoffice把doc转换成Pdf
- linux & windows porting
- docker 部署cassandra
- docker 部署cassandra
- linux内核研究(二)
- Linux实用工具(一)
- Centos中文输入法安装以及切换
- opencv内存管理器2-cvSeqPartition聚类
- OpenCV中IplImage图像格式与BYTE图像数据的转换
- 架构师之我见
- opensession和getCurrentSession区别
- Linux的启动过程或启动顺序
- 自定义注解实现AOP日志记录
- shell初涉
- Linux下ffmpeg安装与开发配置