利用minAreaRect计算平面矩形的旋转角度
2017-02-27 15:51
549 查看
#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"27 using 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
相关文章推荐
- 利用minAreaRect计算平面矩形的旋转角度
- 利用minAreaRect求轮廓最小外接矩形
- opencv 寻找最小矩形minAreaRect 的角度问题
- 在平面内,已知一个矩形的四个角坐标,将矩形绕中心点转动一个角度,求旋转后的角坐标.
- 【opencv】最小包围矩形minAreaRect与最小包围圆minEnclosingCircl详解
- python opencv minAreaRect 生成最小外接矩形
- Opencv获取最小外接矩形——minAreaRect
- opencv6-最小外接矩形minAreaRect
- 计算矩形旋转角度(不精确)
- 利用三维旋转矩阵在空间中旋转平面
- 通过程序设计几何图形(Shape)、矩形(Rectangle)、圆形(Circle)、正方形(Square)几种类型,能够利用接口和多态性计算几何图形的面积和周长并显示。
- 通过程序设计几何图形(Shape)、矩形(Rectangle)、圆形(Circle)、正方形(Square)几种类型, 能够利用接口和多态性计算几何图形的面积和周长并显示
- 为轮廓创建可倾斜的边界框和椭圆-- minAreaRect()和fitEllipse()
- unity3d Quaternion 计算3D物体旋转角度
- 使用EmguCv计算包围物体的最小圆与最小可旋转矩形和不可选择矩形
- 计算两个旋转矩形的交集——Python
- 贴片机中计算PCB板旋转角度的方法
- 通过程序设计几何图形、矩形、圆形、正方形几种类型,能够利用接口和多态性计算几何图形的面积和周长并显示。
- 1.创建一个Rectangle类,添加width和height两个成员变量。 2.在Rectangle中添加两种方法分别计算矩形的周长和面积 3.编程利用Rectangle输出一个矩形的周
- 程序设计几何图形、矩形、圆形、正方形几种类型, 能够利用接口和多态性计算几何图形的面积和周长并显示。