利用minAreaRect计算平面矩形的旋转角度
来源:互联网 发布:list转json后的格式 编辑:程序博客网 时间:2024/05/17 00:49
#include "opencv2/core/core.hpp" #include "opencv2/highgui/highgui.hpp" #include "opencv2/imgproc/imgproc.hpp" #include "opencv2/features2d/features2d.hpp" //需要添加该头文件 #include <iostream> #include "Math.h"27using namespace cv;using namespace std;int main(){ float angle = 0; Mat image(200, 400, CV_8UC3, Scalar(0)); RotatedRect originalRect; Point2f vertices[4]; vector<Point2f> vertVect; RotatedRect calculatedRect; while (waitKey(5000) != 27) { // Create a rectangle, rotating it by 10 degrees more each time. originalRect = RotatedRect(Point2f(100, 100), Size2f(100, 50), angle); // Convert the rectangle to a vector of points for minAreaRect to use. // Also move the points to the right, so that the two rectangles aren't // in the same place. originalRect.points(vertices); for (int i = 0; i < 4; i++) { vertVect.push_back(vertices[i] + Point2f(200, 0)); } // Get minAreaRect to find a rectangle that encloses the points. This // should have the exact same orientation as our original rectangle. calculatedRect = minAreaRect(vertVect); // Draw the original rectangle, and the one given by minAreaRect. for (int i = 0; i < 4; i++) { line(image, vertices[i], vertices[(i + 1) % 4], Scalar(0, 255, 0)); line(image, vertVect[i], vertVect[(i + 1) % 4], Scalar(255, 0, 0)); } imshow("rectangles", image); // Print the angle values. printf("---\n"); printf("Original angle: %7.2f\n", angle); printf("Angle given by minAreaRect: %7.2f\n", calculatedRect.angle); printf("---\n"); // Reset everything for the next frame. image = Mat(200, 400, CV_8UC3, Scalar(0)); vertVect.clear(); angle += 10; } return 0;}
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
- 29
- 30
- 31
- 32
- 33
- 34
- 35
- 36
- 37
- 38
- 39
- 40
- 41
- 42
- 43
- 44
- 45
- 46
- 47
- 48
- 49
- 50
- 51
- 52
- 53
- 54
- 55
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
- 29
- 30
- 31
- 32
- 33
- 34
- 35
- 36
- 37
- 38
- 39
- 40
- 41
- 42
- 43
- 44
- 45
- 46
- 47
- 48
- 49
- 50
- 51
- 52
- 53
- 54
- 55
参考:
http://stackoverflow.com/questions/15956124/minarearect-angles-unsure-about-the-angle-returned
原文地址:http://blog.csdn.net/yanxiaopan/article/details/53240098
0 0
- 利用minAreaRect计算平面矩形的旋转角度
- 利用minAreaRect计算平面矩形的旋转角度
- 计算矩形旋转角度(不精确)
- 利用minAreaRect求轮廓最小外接矩形
- 计算IE的旋转角度与滤镜
- 计算旋转角度
- Unity 旋转角度计算
- 计算旋转角度
- 平面坐标系下计算3个点的角度
- 提取有角度的形状的最小矩形,求其旋转角度、长宽
- Opencv寻找轮廓的最小外接矩形,并获取矩形的中心点,旋转角度
- opencv6-最小外接矩形minAreaRect
- OpenCV 求外接矩形以及旋转角度
- opencv12-计算物体旋转角度
- 贴片机中计算PCB板旋转角度的方法
- 旋转角度计算(旋转手势)
- 判断一个点是否在旋转过任意角度的矩形内
- HDU 5251 矩形面积 (计算几何+旋转卡壳求覆盖凸包的最小矩形面积)
- 天仙配
- 关于Scrollview嵌套RecyclerView高度显示不全
- 北京阿凡达雪景
- PHP:多维数组排序
- 两个单链表第一个公共结点
- 利用minAreaRect计算平面矩形的旋转角度
- 界面适配华为手机的虚拟按键的解决方案
- linux 不同压缩
- c++上机报告
- 广播实验
- C++上机实验1-项目4
- JQuery easyUI datagrid 排序,使用sorter自定义排序
- 《剑指Offer》2.3数据结构 java版
- html dom