fanfuhan OpenCV 教學107 ~ opencv-107-Brisk特徵提取與描述子匹配

fanfuhan OpenCV 教學107 ~ opencv-107-Brisk特徵提取與描述子匹配

fanfuhan OpenCV 教學107 ~ opencv-107-Brisk特徵提取與描述子匹配


資料來源: https://fanfuhan.github.io/

https://fanfuhan.github.io/2019/05/21/opencv-107/

GITHUB:https://github.com/jash-git/fanfuhan_ML_OpenCV


BRISK(二進制魯棒不變可擴展關鍵點)是一種基於尺度空間不變性類似的ORB特徵描述子的特徵提取算法。BRISK主要步驟可以分為如下兩步:

   ~建立尺度空間金字塔實現關鍵點定位

   ~根據關鍵點生成描述子


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");

	// 创建BRISK
	auto brisk_detector = BRISK::create();
	vector<KeyPoint> kpts_01, kpts_02;
	Mat descriptors1, descriptors2;
	brisk_detector->detectAndCompute(box, Mat(), kpts_01, descriptors1);
	brisk_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

import cv2 as cv

box = cv.imread("D:/images/box.png");
box_in_sence = cv.imread("D:/images/box_in_scene.png");
cv.imshow("box", box)
cv.imshow("box_in_sence", box_in_sence)

# 创建BRISK特征检测器
brisk = cv.BRISK_create()
kp1, des1 = brisk.detectAndCompute(box,None)
kp2, des2 = brisk.detectAndCompute(box_in_sence,None)

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

# 绘制匹配
result = cv.drawMatches(box, kp1, box_in_sence, kp2, matches, None)
cv.imshow("orb-match", result)
cv.waitKey(0)
cv.destroyAllWindows()

發表迴響

你的電子郵件位址並不會被公開。 必要欄位標記為 *