当前位置:网站首页>亚像素级角点检测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
边栏推荐
- centerX: 用中国特色社会主义的方式打开centernet
- 杰理之关于 DAC 输出功率问题【篇】
- Codeforces round 264 (Div. 2) C gargari and Bishop [violence]
- cocos3——8. Implementation Guide for beginners
- HMS Core 机器学习服务打造同传翻译新“声”态,AI让国际交流更顺畅
- Change your posture to do operation and maintenance! GOPs 2022 Shenzhen station highlights first!
- Shell 编程基础
- 从0开始创建小程序
- How-PIL-to-Tensor
- Lingyun going to sea | yidiantianxia & Huawei cloud: promoting the globalization of Chinese e-commerce enterprise brands
猜你喜欢

Use of tensorboard
![Jericho turns on the display icon of the classic Bluetooth hid mobile phone to set the keyboard [chapter]](/img/f4/8464bf9b66a1215265ac873f286688.png)
Jericho turns on the display icon of the classic Bluetooth hid mobile phone to set the keyboard [chapter]

When you go to the toilet, you can clearly explain the three Scheduling Strategies of scheduled tasks

HMS Core 机器学习服务打造同传翻译新“声”态,AI让国际交流更顺畅

2022.6.28

Oauth2协议中如何对accessToken进行校验

CVPR 2022 最佳论文候选 | PIP: 6个惯性传感器实现全身动捕和受力估计

How to verify accesstoken in oauth2 protocol

商城商品的知识图谱构建

input_ delay
随机推荐
杰理之开启经典蓝牙 HID 手机的显示图标为键盘设置【篇】
[2022 national tournament simulation] polygon - computational geometry, binary answer, multiplication
[socket] ① overview of socket technology
mos管实现主副电源自动切换电路,并且“零”压降,静态电流20uA
Matlab Error (Matrix dimensions must agree)
HDU ACM 4578 Transformation-&gt; Segment tree - interval change
Lavel PHP artisan automatically generates a complete set of model+migrate+controller commands
c语言字符串排序
How to find file accessed / created just feed minutes ago
SQL中删除数据
Shell 编程基础
变量、流程控制与游标(MySQL)
硬件之OC、OD、推挽解释
Variables, process control and cursors (MySQL)
Household appliance industry under the "retail is king": what is the industry consensus?
【Swift】学习笔记(一)——熟知 基础数据类型,编码风格,元组,主张
Cocos2d-x box2d physical engine compilation settings
Do you know the five most prominent advantages of E-bidding?
又一百万量子比特!以色列光量子初创公司完成1500万美元融资
leetcode-02(链表题)