fanfuhan OpenCV 教學106 ~ opencv-106-AKAZE特徵與描述子
fanfuhan OpenCV 教學106 ~ opencv-106-AKAZE特徵與描述子
資料來源: https://fanfuhan.github.io/
https://fanfuhan.github.io/2019/05/21/opencv-106/
GITHUB:https://github.com/jash-git/fanfuhan_ML_OpenCV
AKAZE特徵提取算法是局部特徵描述子算法,可以看成是SIFT算法的改進,採用差分擴散分解迭代來提取與嵌入尺度空間,採用與SIFT類似的方法尋找特徵點,在描述子生成階段採用ORB類似的方法生成描述子,但是描述子比ORB多了旋轉不變性特徵。ORB採用LDB方法,AKAZE採用M-LDB。
C++
#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; }
Python
""" 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()