原文:
對於其原理我還沒看過,只是略知道是特徵點檢測的,最近同學用到需要將檢測到的匹配的特徵點輸出來,這才看了一下函式的介面,如果以後用到了原理,再去研究和學習一下,這裡對**進行一下備份:
[cpp]view plain
copy
#include
#include
#include "opencv2/core/core.hpp"
#include "opencv2/features2d/features2d.hpp"
#include "opencv2/highgui/highgui.hpp"
#include "opencv2/nonfree/features2d.hpp"
#include
using
namespace
cv;
using
namespace
std;
void
readme();
/** @function main */
intmain(
intargc,
char
** argv )
mat img_1 = imread( argv[1], cv_load_image_grayscale );
mat img_2 = imread( argv[2], cv_load_image_grayscale );
if( !img_1.data || !img_2.data )
//-- step 1: detect the keypoints using surf detector
intminhessian = 400;
surffeaturedetector detector( minhessian );
std::vectorkeypoints_1, keypoints_2;
detector.detect( img_1, keypoints_1 );
detector.detect( img_2, keypoints_2 );
//-- step 2: calculate descriptors (feature vectors)
surfdescriptorextractor extractor;
mat descriptors_1, descriptors_2;
extractor.compute( img_1, keypoints_1, descriptors_1 );
extractor.compute( img_2, keypoints_2, descriptors_2 );
//-- step 3: matching descriptor vectors using flann matcher
flannbasedmatcher matcher;
std::vector matches;
matcher.match( descriptors_1, descriptors_2, matches );
double
max_dist = 0;
double
min_dist = 100;
//-- quick calculation of max and min distances between keypoints
for(
inti = 0; i
printf("-- max dist : %f \n"
, max_dist );
printf("-- min dist : %f \n"
, min_dist );
//-- draw only "good" matches (i.e. whose distance is less than 2*min_dist )
//-- ps.- radiusmatch can also be used here.
std::vector good_matches;
for(
inti = 0; i
} cout<
<
cout<
<
mat img_matches;
//-- draw only "good" matches
#if 1
drawmatches( img_1, keypoints_1, img_2, keypoints_2,
good_matches, img_matches, scalar::all(-1), scalar::all(-1),
vector
>(), drawmatchesflags::not_draw_single_points );
#endif
#if 0
drawmatches( img_1, keypoints_1, img_2, keypoints_2,
matches, img_matches, scalar::all(-1), scalar::all(-1),
vector
>(), drawmatchesflags::not_draw_single_points );
#endif
//-- show detected matches
imshow( "good matches"
, img_matches );
#if 1
//在原影象上顯示匹配的點
//顏色分別為:0綠色,1黃色,2白色,3紅色,4淺藍色,5藍色,6黑色
string strs=;
scalar colors[7]=;
mat img1_1(img_1.rows,img_1.cols,cv_8uc3);
mat img2_2(img_1.rows,img_1.cols,cv_8uc3);
cvtcolor(img_1,img1_1,cv_gray2bgr);
cvtcolor(img_2,img2_2,cv_gray2bgr);
cout<
<
for(
intj=0;j
#endif
#if 0
for(
intj=0;j
#endif
imshow("img1_1"
,img1_1);
imshow("img2_2"
,img2_2);
for(
inti = 0; i
waitkey(0);
return
0;
} /** @function readme */
void
readme()
用surf描述子計算每一張的特徵點,然後利用flann演算法將兩張影象的特徵點進行匹配。匹配的資訊儲存在vector型別的容器中,我們通過下表操作符獲取乙個dmatch物件,該物件的queryidx和queryidx用來標識該點在keypoints中的位置。故利用keypoints[matches[i].queryidx]可以訪問到關鍵點(特徵點物件),然後利用特徵點物件的座標成員pt,即得到了特徵點的x和y的座標。我們通過才彩色影象上畫出來標識他們的一一對應,**如下:
[cpp]view plain
copy
scalar colors[7]=;
mat img1_1(img_1.rows,img_1.cols,cv_8uc3);
mat img2_2(img_1.rows,img_1.cols,cv_8uc3);
cvtcolor(img_1,img1_1,cv_gray2bgr);
cvtcolor(img_2,img2_2,cv_gray2bgr);
for(
intj=0;j
執行**,效果如下:
特徵檢測演算法 SURF
reference surf 演算法,全稱是 speeded up robust features。該運算元在保持 sift 運算元優良效能特點的基礎上,同時解決了 sift 計算複雜度高 耗時長的缺點,對興趣點提取及其特徵向量描述方面進行了改進,且計算速度得到提高。具體步驟為 1 構造hessia...
surf特徵檢測描述和匹配
include include include opencv2 core core.hpp include opencv2 features2d features2d.hpp include opencv2 highgui highgui.hpp include includeusing names...
opencv 33 SURF特徵檢測
surf speededup robust features 加速穩健特徵演算法,在2006 年由bay.h和van gool.l共同提出,surf是尺度不變特徵變換sift的加速版。一般來說,標準的surf運算元比sift運算元快好幾倍,並且在多幅影象下具有更好的穩定性。surf最大的特徵在於採用...