[opencv]KAZE、AKAZE特征检测、匹配与对象查找
2024-10-19 23:39:20
AkAZE是KAZE的加速版
与SIFT,SUFR比较:
1.更加稳定
2.非线性尺度空间
3.AKAZE速度更加快
4.比较新的算法,只有Opencv新的版本才可以用
AKAZE局部匹配介绍
1.AOS构造尺度空间
2.Hessian矩阵特征点
3.方向指定基于一阶微分图像
4.描述子生成
特征点查找和绘制:把surf中的surf改成KAZE或AKAZE即可
#include <opencv2/opencv.hpp>
#include <opencv2/features2d.hpp>
#include <iostream> using namespace cv;
using namespace cv::features2d;
using namespace std; int Akaze feature detection(){
Mat src = imread("test.jpg", IMREAD_GRAYSCALE);
if (src.empty()) {
printf("could not load image...\n");
return -1;
}
namedWindow("input image", CV_WINDOW_AUTOSIZE);
imshow("input image", src); // AKAZE特征点检测
Ptr<AKAZE> detector = AKAZE::create();//创建一个AKAZE类对象并初始化
vector<KeyPoint> keypoints;
detector->detect(src, keypoints, Mat());//找Mat src = imread("test.jpg", IMREAD_GRAYSCALE);
if (src.empty()) {
printf("could not load image...\n");
return -1;
}
namedWindow("input image", CV_WINDOW_AUTOSIZE);
imshow("input image", src); // AKAZE特征点检测
Ptr<AKAZE> detector = AKAZE::create();//创建一个AKAZE类对象并初始化
vector<KeyPoint> keypoints;
detector->detect(src, keypoints, Mat());//找出关键点 // 绘制关键点
Mat keypoint_img;
drawKeypoints(src, keypoints, keypoint_img, Scalar::all(-1), DrawMatchesFlags::DEFAULT);
imshow("KeyPoints Image", keypoint_img); waitKey(0);
return 0;
}
匹配:
int featurematching{ Mat img1 = imread("/home/leoxae/KeekoRobot/TestPic/qrcodetest/13.png");
Mat img2 = imread("/home/leoxae/KeekoRobot/TestPic/qrcodetest/13.png"); imshow("box image", img1);
imshow("scene image", img2); // extract akaze features
Ptr<AKAZE> detector = AKAZE::create();
vector<KeyPoint> keypoints_obj;
vector<KeyPoint> keypoints_scene;
Mat descriptor_obj, descriptor_scene;
detector->detectAndCompute(img1, Mat(), keypoints_obj, descriptor_obj);
detector->detectAndCompute(img2, Mat(), keypoints_scene, descriptor_scene); // matching
FlannBasedMatcher matcher(new flann::LshIndexParams(20, 10, 2));
//FlannBasedMatcher matcher;
vector<DMatch> matches;
matcher.match(descriptor_obj, descriptor_scene, matches); // draw matches(key points)
Mat akazeMatchesImg;
/*
drawMatches(img1, keypoints_obj, img2, keypoints_scene, matches, akazeMatchesImg);
imshow("akaze match result", akazeMatchesImg);*/ vector<DMatch> goodMatches;
double minDist = 100000, maxDist = 0;
for (int i = 0; i < descriptor_obj.rows; i++) {
double dist = matches[i].distance;
if (dist < minDist) {
minDist = dist;
}
if (dist > maxDist) {
maxDist = dist;
}
}
printf("min distance : %f", minDist); for (int i = 0; i < descriptor_obj.rows; i++) {
double dist = matches[i].distance;
if (dist < max( 1.5*minDist, 0.02)) {
goodMatches.push_back(matches[i]);
}
} drawMatches(img1, keypoints_obj, img2, keypoints_scene, goodMatches, akazeMatchesImg, Scalar::all(-1),
Scalar::all(-1), vector<char>(), DrawMatchesFlags::NOT_DRAW_SINGLE_POINTS);
imshow("good match result", akazeMatchesImg);
waitKey(0);
}
最新文章
- 大量数据快速导出的解决方案-Kettle
- Add和AddRange的区别
- 窗口 - dialog - 概述与基本使用
- FindinFiles - Windows文件内查找插件
- c# &; Fizzler to crawl web page in a certain website domain
- 【转】Solr5.3.1定时增量添加索引和重做索引
- Ajax+Asp.Net无刷新分页
- (转)Spring中Bean的命名问题(id和name区别)及ref和idref之间的区别
- 使用SQLite3持久保存应用程序数据
- 关于Eclipse Modeling Framework 实现模型驱动开发,第一部分
- Hdu3812-Sea Sky(深搜+剪枝)
- 2015 5.16 C# 继承和多态
- Shell出现cd命令无法识别
- Token验证失败的解决方法
- webpack教程(二)——webpack.config.js文件
- php实现查询上传文件进度
- DRF之接口文档以及Xadmin
- ZSetOperations 操作解释 拷贝过来的 哈哈哈
- 7. Bagging &; Random Forest
- UiTextField 限制输入长度