opencv-106-AKAZE特征与描述子

知识点

AKAZE特征提取算法是局部特征描述子算法,可以看成是SIFT算法的改进、采用非线性扩散滤波迭代来提取与构建尺度空间、采用与SIFT类似的方法寻找特征点、在描述子生成阶段采用ORB类似的方法生成描述子,但是描述子比ORB多了旋转不变性特征。ORB采用LDB方法,AKAZE采用 M-LDB。

代码(c++,python)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
#include <opencv2/opencv.hpp>
#include <iostream>

using namespace cv;
using namespace std;

int main(int argc, char** argv) {
Mat box = imread("D:/images/box.png");
Mat box_in_sence = imread("D:/images/box_in_scene.png");

// 创建AKAZE
auto akaze_detector = AKAZE::create();
vector<KeyPoint> kpts_01, kpts_02;
Mat descriptors1, descriptors2;
akaze_detector->detectAndCompute(box, Mat(), kpts_01, descriptors1);
akaze_detector->detectAndCompute(box_in_sence, Mat(), kpts_02, descriptors2);

// 定义描述子匹配 - 暴力匹配
Ptr<DescriptorMatcher> matcher = DescriptorMatcher::create(DescriptorMatcher::BRUTEFORCE);
std::vector< DMatch > matches;
matcher->match(descriptors1, descriptors2, matches);

// 绘制匹配
Mat img_matches;
drawMatches(box, kpts_01, box_in_sence, kpts_02, matches, img_matches);
imshow("AKAZE-Matches", img_matches);
imwrite("D:/result.png", img_matches);

waitKey(0);
return 0;
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
"""
AKAZE特征与描述子
"""

import cv2 as cv

box = cv.imread("images/box.png")
box_in_scene = cv.imread("images/box_in_scene.png")

# 创建AKAZE特征检测器
akaze = cv.AKAZE_create()

# 得到特征关键点和描述子
kp1, des1 = akaze.detectAndCompute(box, None)
kp2, des2 = akaze.detectAndCompute(box_in_scene, None)

# 暴力匹配
bf = cv.BFMatcher(cv.NORM_HAMMING, crossCheck=True)
matchers = bf.match(des1, des2)

# 绘制匹配
result = cv.drawMatches(box, kp1, box_in_scene, kp2, matchers, None)
cv.imshow("orb-match", result)

cv.waitKey(0)
cv.destroyAllWindows()

结果

代码地址

github