opencv AKAZE 局部特征匹配算法
Posted qianbo_insist
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了opencv AKAZE 局部特征匹配算法相关的知识,希望对你有一定的参考价值。
AKAZE 局部特征匹配
级联分类器使用
等比例缩放图片
给图片加logo
鱼眼校正
智能答卷识别
opencv滤镜效果
灰度图像增强方式
基础知识点
AKAZE特征提取算法是局部特征描述子算法,是SIFT算法的改进、采用非线性扩散滤波迭代来提取与构建尺度空间、采用与SIFT类似的方法寻找特征点,
1 在描述子生成阶段采用ORB类似的方法生成描述子
2 描述子比ORB多了旋转不变性特征
3 ORB采用LDB方法,KAZE采用 M-LDB。
orb算法获取尺度不变性,构建了图像金字塔,在金字塔的每一层上都检测关键点。AKAZE则是改进算法。实际上,把AKAKE改成ORB就是执行ORB算法
//opencv里面,修改算法名称即可
Ptr<ORB> detector = ORB::create(minHessian);/
Ptr<AKAZE> detector = AKAZE::create();
找出关键点很简单,就是下面做法
vector<KeyPoint> keypoints;
detector->detect(src, keypoints, Mat());//找出关键点
show me the code
#include <opencv2/opencv.hpp>
#include <iostream>
#include <math.h>
using namespace cv;
using namespace std;
int main(int argc, char** argv) {
Mat img1 = imread("in.jpg", IMREAD_GRAYSCALE);
Mat img2 = imread("big2.jpg", IMREAD_GRAYSCALE);
if (img1.empty() || img2.empty()) {
printf("could not load images...\\n");
return -1;
}
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);
return 0;
}
下面为大图
小图
以上是关于opencv AKAZE 局部特征匹配算法的主要内容,如果未能解决你的问题,请参考以下文章