[opencv]利用minAreaRect计算平面矩形的旋转角度
#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;
}
[opencv]利用minAreaRect计算平面矩形的旋转角度的更多相关文章
- 利用sklearn计算文本相似性
利用sklearn计算文本相似性,并将文本之间的相似度矩阵保存到文件当中.这里提取文本TF-IDF特征值进行文本的相似性计算. #!/usr/bin/python # -*- coding: utf- ...
- 利用Python计算π的值,并显示进度条
利用Python计算π的值,并显示进度条 第一步:下载tqdm 第二步;编写代码 from math import * from tqdm import tqdm from time import ...
- 计算平面面积和斜面面积-ArcGIS案例学习笔记
计算平面面积和斜面面积-ArcGIS案例学习笔记 联系方式:谢老师,135_4855_4328,xiexiaokui#139.com 数据:实验数据\Chp8\Ex5\demTif.tif 平面面积= ...
- Ajax实例一:利用服务器计算
Ajax实例一:利用服务器计算 HTML代码 //输入两个数 <input id="number1" type="number"> <inpu ...
- 利用函数计算构建微信小程序的Server端
10分钟上线 - 利用函数计算构建微信小程序的Server端-博客-云栖社区-阿里云 https://yq.aliyun.com/articles/435430 函数计算 读写 oss import ...
- 【改革春风吹满地 HDU - 2036 】【计算几何-----利用叉积计算多边形的面积】
利用叉积计算多边形的面积 我们都知道计算三角形的面积时可以用两个邻边对应向量积(叉积)的绝对值的一半表示,那么同样,对于多边形,我们可以以多边形上的一个点为源点,作过该点并且过多边形其他点中的某一个的 ...
- EDU 50 E. Covered Points 利用克莱姆法则计算线段交点
E. Covered Points 利用克莱姆法则计算线段交点.n^2枚举,最后把个数开方,从ans中减去. ans加上每个线段的定点数, 定点数用gcs(△x , △y)+1计算. #include ...
- MergeSort归并排序和利用归并排序计算出数组中的逆序对
首先先上LeetCode今天的每日一题(面试题51. 数组中的逆序对): 在数组中的两个数字,如果前面一个数字大于后面的数字,则这两个数字组成一个逆序对.输入一个数组,求出这个数组中的逆序对的总数. ...
- OpenCV 求外接矩形以及旋转角度
程序没有写完整,大概功能就是实现了,希望大家分享学习,把他改对 // FindRotation-angle.cpp : 定义控制台应用程序的入口点. // // findContours.cpp : ...
随机推荐
- windows磁盘扩容
要邻近的磁盘,才可以扩展.所以必须要先删除恢复分区. 删除恢复分区,参考如下: https://jingyan.baidu.com/article/574c5219598d5e6c8c9dc15e.h ...
- 打破砂锅问到底!HTTP和HTTPS详解
HTTP 引自维基百科HTTP:超文本传输协议(英文:HyperText Transfer Protocol,缩写:HTTP)是一种用于分布式.协作式和超媒体信息系统的应用层协议.HTTP是万维网的数 ...
- 编程之美Q1
题目 和数书页有点类似,就直接数吧 #include<iostream> using namespace std; class q1 { public: size_t func(size_ ...
- jvm的优化
a) 设置参数,设置jvm的最大内存数 b) 垃圾回收器的选择
- BlockingQueue的基本原理
1. 前言 BlockingQueue即阻塞队列,它算是一种将ReentrantLock用得非常精彩的一种表现,依据它的基本原理,我们可以实现Web中的长连接聊天功能,当然其最常用的还是用于实现生产者 ...
- React 传值 组件传值 之间的关系
react 组件相互之间的传值: 传值分父级组件传值给子组件 子组件传值给父组件 平级组件.没有嵌套的组件相互传值 1.父组件向子组件传值 父组件通过属性的形式来向子组件传值,子组件通过pr ...
- idea集成开发工具快捷键大全
1 执行(run) alt+r 2 提示补全 (Class Name Completion) ...
- 【VSCode】检测到 #include 错误。请更新 includePath。已为此翻译单元(C:\mingw-w64\i686-8.1.0-posix-dwarf-rt_v6-rev0\mingw32\i686-
win+r 运行cmd 输入"gcc -v -E -x c -"获取mingw路径: 我的: #include "..." search starts here ...
- Nginx中指令
Rewrite模块 1 return指令 Syntax: return code [text]; return code URL; return URL; Default: - Context: se ...
- Linux中定时任务
目录 一.简介 二.crondtab file 三.crond命令的调试 四.精确到秒的任务计划 一.简介 定时任务在线测试网站 定时任务基本概念: (1).crond是一个daemon类程序,路径为 ...