opencv3/C++ FLANN特征匹配方式
使用函數(shù)detectAndCompute()檢測(cè)關(guān)鍵點(diǎn)并計(jì)算描述符
函數(shù)detectAndCompute()參數(shù)說(shuō)明:
void detectAndCompute( InputArray image, //圖像 InputArray mask, //掩模 CV_OUT std::vector<KeyPoint>& keypoints,//輸出關(guān)鍵點(diǎn)的集合 OutputArray descriptors,//計(jì)算描述符(descriptors[i]是為keypoints[i]的計(jì)算描述符) bool useProvidedKeypoints=false //使用提供的關(guān)鍵點(diǎn) );
match()從查詢(xún)集中查找每個(gè)描述符的最佳匹配。
參數(shù)說(shuō)明:
void match( InputArray queryDescriptors, //查詢(xún)描述符集 InputArray trainDescriptors, //訓(xùn)練描述符集合 CV_OUT std::vector<DMatch>& matches, //匹配 InputArray mask=noArray() //指定輸入查詢(xún)和描述符的列表矩陣之間的允許匹配的掩碼 ) const;
FLANN特征匹配示例:
#include<opencv2/opencv.hpp>
#include<opencv2/xfeatures2d.hpp>
using namespace cv;
using namespace cv::xfeatures2d;
//FLANN對(duì)高維數(shù)據(jù)較快
int main()
{
Mat src1,src2;
src1 = imread("E:/image/image/card2.jpg");
src2 = imread("E:/image/image/cards.jpg");
if (src1.empty() || src2.empty())
{
printf("can ont load images....\n");
return -1;
}
imshow("image1", src1);
imshow("image2", src2);
int minHessian = 400;
//選擇SURF特征
Ptr<SURF>detector = SURF::create(minHessian);
std::vector<KeyPoint>keypoints1;
std::vector<KeyPoint>keypoints2;
Mat descriptor1, descriptor2;
//檢測(cè)關(guān)鍵點(diǎn)并計(jì)算描述符
detector->detectAndCompute(src1, Mat(), keypoints1, descriptor1);
detector->detectAndCompute(src2, Mat(), keypoints2, descriptor2);
//基于Flann的描述符匹配器
FlannBasedMatcher matcher;
std::vector<DMatch>matches;
//從查詢(xún)集中查找每個(gè)描述符的最佳匹配
matcher.match(descriptor1, descriptor2, matches);
double minDist = 1000;
double maxDist = 0;
for (int i = 0; i < descriptor1.rows; i++)
{
double dist = matches[i].distance;
printf("%f \n", dist);
if (dist > maxDist)
{
maxDist = dist;
}
if (dist < minDist)
{
minDist = dist;
}
}
//DMatch類(lèi)用于匹配關(guān)鍵點(diǎn)描述符的
std::vector<DMatch>goodMatches;
for (int i = 0; i < descriptor1.rows; i++)
{
double dist = matches[i].distance;
if (dist < max(2.5*minDist, 0.02))
{
goodMatches.push_back(matches[i]);
}
}
Mat matchesImg;
drawMatches(src1, keypoints1, src2, keypoints2, goodMatches, matchesImg, Scalar::all(-1), Scalar::all(-1), std::vector<char>(), DrawMatchesFlags::NOT_DRAW_SINGLE_POINTS);
imshow("output", matchesImg);
waitKey();
return 0;
}



以上這篇opencv3/C++ FLANN特征匹配方式就是小編分享給大家的全部?jī)?nèi)容了,希望能給大家一個(gè)參考,也希望大家多多支持腳本之家。
相關(guān)文章
淺談2路插入排序算法及其簡(jiǎn)單實(shí)現(xiàn)
這篇文章主要介紹了淺談2路插入排序算法及其簡(jiǎn)單實(shí)現(xiàn),雖算不上是常用的排序方法,但在數(shù)據(jù)庫(kù)等方面依然有用上的機(jī)會(huì),需要的朋友可以參考下2015-08-08
C語(yǔ)言實(shí)現(xiàn)字符串替換的示例代碼
本文主要介紹了C語(yǔ)言實(shí)現(xiàn)字符串替換的示例代碼,文中通過(guò)示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2022-01-01
C字符串函數(shù)對(duì)應(yīng)的C++ string操作詳解
在本篇文章里小編給大家整理的是一篇關(guān)于C字符串函數(shù)對(duì)應(yīng)的C++ string操作知識(shí)點(diǎn)內(nèi)容,有興趣的朋友們學(xué)習(xí)下。2020-01-01
利用C語(yǔ)言實(shí)現(xiàn)簡(jiǎn)單三子棋游戲
這篇文章主要為大家詳細(xì)介紹了利用C語(yǔ)言實(shí)現(xiàn)簡(jiǎn)單三子棋游戲,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2021-03-03
C++利用類(lèi)實(shí)現(xiàn)矩陣的數(shù)乘,乘法以及點(diǎn)乘
這篇文章主要為大家詳細(xì)介紹了C++如何利用類(lèi)實(shí)現(xiàn)矩陣的數(shù)乘,乘法以及點(diǎn)乘,文中的示例代碼講解詳細(xì),對(duì)我們學(xué)習(xí)C++有一定幫助,需要的可以參考一下2022-11-11
C語(yǔ)言修煉之路初識(shí)指針陰陽(yáng)竅?地址還歸大道真上篇
指針是指向另一個(gè)變量的變量。意思是一個(gè)指針保存的是另一個(gè)變量的內(nèi)存地址。換句話(huà)說(shuō),指針保存的并不是普通意義上的數(shù)值,而是另一個(gè)變量的地址值。一個(gè)指針保存了另一個(gè)變量的地址值,就說(shuō)這個(gè)指針“指向”了那個(gè)變量2022-02-02
基于C語(yǔ)言實(shí)現(xiàn)簡(jiǎn)單的走迷宮游戲
這篇文章主要介紹了基于C語(yǔ)言實(shí)現(xiàn)簡(jiǎn)單的走迷宮游戲,用到雙向隊(duì)列,方便在運(yùn)行完畢后輸出經(jīng)過(guò)的點(diǎn),文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2016-04-04

