当前位置:网站首页>亚像素级角点检测Opencv-cornerSubPix
亚像素级角点检测Opencv-cornerSubPix
2022-07-06 20:07:00 【马少爷】
Opencv-cornerSubPix原理介绍
若我们进行图像处理的目的不是提取用于识别的特征点而是进行几何测量,这通常需要更高的精度,而函数 goodFeaturesToTrack() 只能提供简单的像素的坐标值,也就是说有时会需要实数坐标值而不是整数坐标值。
角点位置特征:角点与边缘点的连线和边缘点的梯度方向垂直。
如上图所示,假设一个起始角点 q 在实际亚像素角点附近。
p 点在 q 点附近的邻域中,若 p 点在均匀区域内部,则 p 点的梯度为0;若 p 点在边缘上,则 p 点的梯度方向垂直边缘方向。如果向量 q-p 方向与边缘方向一致,那么 q-p 向量与 p 点的梯度向量点积运算结果为 0 。
在初始角点(初始角点可能不在边缘上)附近我们可以收集很多组点的梯度以及相关向量 q-p ,此时的 q 就是我们所要求的更精确角点位置,那么每一组的向量点积设置为 0 ,正是基于这个思想,将点积为 0 的等式组合起来形成一个系统方程,该系统方程的解就是更精确的亚像素角点位置。 将新的 q 点作为区域的中心,可以继续使用这个方法进行迭代,获得很高的精度。
寻找亚像素角点:cornerSubPix 函数
void cornerSubPix(InputArray image, InputOutputArray corners, Size winSize, Size zeroZone, TermCriteria criteria);
image,输入图像,即源图像。
corners,提供输入角点的初始坐标和精确的输出坐标。
winSize,搜索窗口的一半尺寸。若 winSize = Size(5,5),那就表示用(52+1)×(52+1)= 11×11 大小的搜索窗口。
zeroZone,死区的一半尺寸。真正搜索区域为 [zeroZone2+1 , winSize2+1]。值为(-1,-1)表示没有死区。
criteria,求角点的迭代过程的终止条件。要么是迭代数大于某个设定值,要么是精度达到某个设定值,甚至可以是它们的组合。
#include<opencv.hpp>
#include<iostream>
#include<string>
#include<vector>
using namespace std;
using namespace cv;
Mat src, cornerImg, grayImg;
int mxCorners = 10;
RNG rngs = {
12345 };
void Change(int, void*) {
//计算整数角点
vector<Point>corners1;
vector<Point2f>corners2; //https://www.cnblogs.com/bjxqmy/p/12459005.html
goodFeaturesToTrack(grayImg, corners1, mxCorners, 0.01, 10, Mat(), 3, false, 0.04);
goodFeaturesToTrack(grayImg, corners2, mxCorners, 0.01, 10, Mat(), 3, false, 0.04);
//计算精确角点
TermCriteria criteria = TermCriteria(TermCriteria::EPS + TermCriteria::MAX_ITER, 40, 0.001);
cornerSubPix(grayImg, corners2, Size(5, 5), Size(-1, -1), criteria);
Mat dst = src.clone();
for (int i = 0; i < corners1.size(); i++) {
cout << "[" << corners1[i].x << "," << corners1[i].y << "]" << endl;
cout << "[" << corners2[i].x << "," << corners2[i].y << "]" << endl << endl;
Scalar colors = Scalar(rngs.uniform(0, 255), rngs.uniform(0, 255), rngs.uniform(0, 255));
circle(dst, corners2[i], 5, colors, -1);
}
imshow("dst", dst);
}
int main() {
src = imread("C:/Users/齐明洋/Desktop/示例图片/1.jpg");
imshow("src", src);
//转换为灰度图像
cvtColor(src, grayImg, COLOR_BGR2GRAY);
namedWindow("dst");
createTrackbar("maxCorners", "dst", &mxCorners, 100, Change);
Change(0, 0);
waitKey(0);
}
参考来源:https://blog.csdn.net/weixin_41695564/article/details/79991733
边栏推荐
- C language string sorting
- [2022 national tournament simulation] polygon - computational geometry, binary answer, multiplication
- Decoration design enterprise website management system source code (including mobile source code)
- A complete tutorial for getting started with redis: problem location and optimization
- 杰理之开启经典蓝牙 HID 手机的显示图标为键盘设置【篇】
- The whole process of knowledge map construction
- 简单冒泡排序
- The first symposium on "quantum computing + application of financial technology" was successfully held in Beijing
- Flink task exit process and failover mechanism
- 凌云出海记 | 易点天下&华为云:推动中国电商企业品牌全球化
猜你喜欢
Error: could not find a version that satisfies the requirement xxxxx (from versions: none) solutions
Es6中Promise的使用
Significance and measures of source code confidentiality
Flink Task退出流程与Failover机制
Redis getting started complete tutorial: replication topology
When you go to the toilet, you can clearly explain the three Scheduling Strategies of scheduled tasks
Change your posture to do operation and maintenance! GOPs 2022 Shenzhen station highlights first!
[socket] ① overview of socket technology
[tools] basic concept of database and MySQL installation
Variables, process control and cursors (MySQL)
随机推荐
DOMContentLoaded和window.onload
从 1.5 开始搭建一个微服务框架——日志追踪 traceId
Stored procedures and functions (MySQL)
Variables, process control and cursors (MySQL)
Flink task exit process and failover mechanism
你知道电子招标最突出的5大好处有哪些吗?
杰理之关于 DAC 输出功率问题【篇】
[Dameng database] after backup and recovery, two SQL statements should be executed
Redis getting started complete tutorial: replication configuration
房费制——登录优化
Uniapp adaptation problem
Lost in the lock world of MySQL
Es6中Promise的使用
tensorboard的使用
存储过程与函数(MySQL)
掘金量化:通过history方法获取数据,和新浪财经,雪球同用等比复权因子。不同于同花顺
2022.6.28
How to find file accessed / created just feed minutes ago
[cpk-ra6m4 development board environment construction based on RT thread studio]
Jerry's RTC clock development [chapter]