#include #include #include "opencv2/core/core.hpp"
#include "opencv2/features2d/features2d.hpp"
#include "opencv2/highgui/highgui.hpp"
#include #includeusing namespace cv;
using namespace std;
void readme();
/** @function main */
int main(int argc, char** argv)
//-- step 1: detect the keypoints using surf detector
int minhessian = 400;
surffeaturedetector detector(minhessian);//定義最大特徵數400
std::vectorkeypoints_1, keypoints_2;//opencv裡為角點檢測提供了統一的介面,通過類下面的detect方法來檢測對應的角點,而輸出格式都是vectordetector.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);//提取surf特徵點以及其描述
extractor.compute(img_2, keypoints_2, descriptors_2);
//-- step 3: matching descriptor vectors with a brute force matcher計算匹配點數
bruteforcematcher< l2> matcher;
std::vector< dmatch > matches;
matcher.match(descriptors_1, descriptors_2, matches);
/*void match(const mat& querydescriptors, const mat& traindescriptors,
cv_out vector& matches, const mat& mask = mat()) const;
*///匹配點向量和畫圖
int w = img_1.cols;
int h = img_1.rows;
mat showimg(h, 2*w, cv_8uc1, scalar(0, 0, 0));
img_1.copyto(showimg(rect(0, 0, w,h)));
img_2.copyto(showimg(rect(w, 0, w,h)));
vectorfeture_matche[2];
for (int i = 0; i < matches.size(); ++i)
for (int i = 0; i < feture_matche[0].size(); i++)
cout << "圖1已經匹配的特徵點座標p1" << i << "=" << feture_matche[0][i] << " " << "圖2已經匹配的特徵點座標p2" << i << "=" << feture_matche[1][i] << endl;
cout << matches.size() << " " << feture_matche[0].size() << " " << feture_matche[1].size() << endl;//這三個數是相等的
imshow("match", showimg);
//只提取25個匹配點並畫出
std::nth_element(matches.begin(), matches.begin() + 24, matches.end());
matches.erase(matches.begin() + 25, matches.end());
//-- draw matches
mat img_matches;
drawmatches(img_1, keypoints_1, img_2, keypoints_2, matches, img_matches,scalar(255, 0, 0));//未定義顏色則將畫出不同顏色匹配線條
Surf特徵檢測
原文 對於其原理我還沒看過,只是略知道是特徵點檢測的,最近同學用到需要將檢測到的匹配的特徵點輸出來,這才看了一下函式的介面,如果以後用到了原理,再去研究和學習一下,這裡對 進行一下備份 cpp view plain copy include include include opencv2 core ...
SURF 特徵匹配
參考 博主對原始碼進行了分析,不過很多沒看明白。分為幾個部分。積分圖 借助積分影象,影象與高斯二階微分模板的濾波轉化為對積分影象的加減運算。在哈爾特徵中也用到這個。doh近似 將模板與圖產像的卷積轉換為盒子濾波運算,我們需要對高斯二階微分模板進行簡化,進而對hessian矩陣行列式的值進行簡化。使用...
特徵檢測演算法 SURF
reference surf 演算法,全稱是 speeded up robust features。該運算元在保持 sift 運算元優良效能特點的基礎上,同時解決了 sift 計算複雜度高 耗時長的缺點,對興趣點提取及其特徵向量描述方面進行了改進,且計算速度得到提高。具體步驟為 1 構造hessia...