search
尋找貓咪~QQ 地點 桃園市桃園區 Taoyuan , Taoyuan

fanfuhan OpenCV 教學095 ~ opencv-095-ORB之BRIEF特徵描述子比對/匹配 – jashliao部落格

fanfuhan OpenCV 教學095 ~ opencv-095-ORB之BRIEF特徵描述子比對/匹配


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

https://fanfuhan.github.io/2019/05/10/opencv-095/

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


得到特徵點數據之後,根據BRIEF算法就可以建立描述子。選擇候選特徵點周圍SxS大小的像素塊、隨機選擇n對像素點。其中P(x)是圖像模糊處理之後的像素值,原因在於高斯模糊可以抑制噪聲影響、提供特徵點穩定性,在實際代碼實現中通常用均值濾波替代高斯濾波以便利用積分圖方式加速計算獲得更好的性能表現。常見濾波時候使用3×3~9×9之間的捲積核。濾波之後,根據上述描述子的生成條件,得到描述子。

作者論文提到n的取值通常為128、256或者512。得到二進制方式的字符串描述子之後,匹配就可以通過XOR方式矩形,計算漢明距離。ORB特徵提取跟純BRIEF特徵提取相比較,BRIEF方式採用隨機點方式得最終描述子、而ORB通過FAST得到特徵點然後得到描述子。


C++

#include 
#include 

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

	// 创建ORB
	auto orb_detector = ORB::create();
	vector kpts_01, kpts_02;
	Mat descriptors1, descriptors2;
	orb_detector->detectAndCompute(box, Mat(), kpts_01, descriptors1);
	orb_detector->detectAndCompute(box_in_sence, Mat(), kpts_02, descriptors2);

	// 定义描述子匹配 - 暴力匹配
	Ptr 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("ORB-Matches", img_matches);
	imwrite("D:/result.png", img_matches);

	waitKey(0);
	return 0;
}

Python

"""
ORB之BRIEF特征描述子匹配
"""

import cv2 as cv

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

# 创建ORB特征检测器
orb = cv.ORB_create()

# 得到特征关键点和描述子
kp1, des1 = orb.detectAndCompute(box, None)
kp2, des2 = orb.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()


熱門推薦

本文由 jashliaoeuwordpress 提供 原文連結

寵物協尋 相信 終究能找到回家的路
寫了7763篇文章,獲得2次喜歡
留言回覆
回覆
精彩推薦