OpenCV20(flann乙個簡單的測試程式)

2021-07-23 13:17:06 字數 2475 閱讀 1154

// flann測試.cpp : 定義控制台應用程式的入口點。

///****於opencv官網,略有修改

* @file surf_flannmatcher

* @brief surf detector + descriptor + flann matcher

* @author a. huaman

*/#include "stdafx.h"

#include "opencv2/opencv_modules.hpp"

#include # include "opencv2/core/core.hpp"

# include "opencv2/features2d/features2d.hpp"

# include "opencv2/highgui/highgui.hpp"

# include "opencv2/nonfree/features2d.hpp"

using namespace cv;

int main( int argc, char** argv )

//-- step 1: detect the keypoints using surf detector

int minhessian = 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 );//計算影象中的特徵點,得到描述符號(descriptor)

extractor.compute( img_2, keypoints_2, descriptors_2 );

//-- step 3: matching descriptor vectors using flann matcher

flannbasedmatcher matcher;

std::vector< dmatch > matches;// dmatch是封裝好的兩個匹配點(匹配對)的一組多個特徵的類,這個matches是用來存放匹配對特徵的向量

matcher.match( descriptors_1, descriptors_2, matches );// 有興趣可以自己看看這個match的實現

double max_dist = 0; double min_dist = 100;

//-- quick calculation of max and min distances between keypoints

for( int i = 0; i < descriptors_1.rows; 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,

//-- or a small arbitary value ( 0.02 ) in the event that min_dist is very

//-- small)

//-- ps.- radiusmatch can also be used here.

std::vector< dmatch > good_matches;

for( int i = 0; i < descriptors_1.rows; i++ )

}//-- draw only "good" matches

mat img_matches;

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

//-- show detected matches

imshow( "good matches", img_matches );

for( int i = 0; i < (int)good_matches.size(); i++ )

waitkey(0);

return 0;

}

第乙個opencv程式

源 如下 hello.c include cv.h include highgui.h int main int argc,char argv return 1 1.編譯 gcc hello.c o hello 報錯如下 hello.c 1 16 錯誤 cv.h 沒有該檔案或目錄 hello.c 2...

第乙個opencv程式

opencv的全稱是 open source computer vision library。opencv是乙個基於 開源 發行的跨平台計算機視覺庫,可以執行在linux windows和mac os作業系統上。它輕量級而且高效 由一系列 c 函式和少量 c 類構成,同時提供了python ruby...

opencv第乙個程式

學習opencv一書中,提到opencv主體一共分為五個模組。其中圖中沒有的模組為沒有包含cvaux模組,該模組中一般存放一些即將被淘汰的演算法和函式 如基於嵌入式隱馬爾可夫模型的人臉識別演算法 同時還有一些新出現的實驗性的演算法和函式 如背景和前景的分割 include using namespa...