OpenCV 特征点检测
生活随笔
收集整理的這篇文章主要介紹了
OpenCV 特征点检测
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
特征點檢測
目標
在本教程中,我們將涉及:
- 使用?FeatureDetector?接口來發現感興趣點。特別地:
- 使用?SurfFeatureDetector?以及它的函數?detect?來實現檢測過程
- 使用函數?drawKeypoints?來繪制檢測到的關鍵點
理論
代碼
這個教程的代碼如下所示。你還可以從?這個鏈接下載到源代碼
#include <stdio.h> #include <iostream> #include "opencv2/core/core.hpp" #include "opencv2/features2d/features2d.hpp" #include "opencv2/highgui/highgui.hpp"using namespace cv;void readme();/** @function main */ int main( int argc, char** argv ) {if( argc != 3 ){ readme(); return -1; }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 ){ std::cout<< " --(!) Error reading images " << std::endl; return -1; }//-- Step 1: Detect the keypoints using SURF Detectorint minHessian = 400;SurfFeatureDetector detector( minHessian );std::vector<KeyPoint> keypoints_1, keypoints_2;detector.detect( img_1, keypoints_1 );detector.detect( img_2, keypoints_2 );//-- Draw keypointsMat img_keypoints_1; Mat img_keypoints_2;drawKeypoints( img_1, keypoints_1, img_keypoints_1, Scalar::all(-1), DrawMatchesFlags::DEFAULT );drawKeypoints( img_2, keypoints_2, img_keypoints_2, Scalar::all(-1), DrawMatchesFlags::DEFAULT );//-- Show detected (drawn) keypointsimshow("Keypoints 1", img_keypoints_1 );imshow("Keypoints 2", img_keypoints_2 );waitKey(0);return 0;}/** @function readme */void readme(){ std::cout << " Usage: ./SURF_detector <img1> <img2>" << std::endl; }解釋
結果
這是第一張圖的特征點檢測結果:
這是第二張圖的特征點檢測:
翻譯者?
Shuai Zheng, <kylezheng04@gmail.com>,?http://www.cbsr.ia.ac.cn/users/szheng/
from:?http://www.opencv.org.cn/opencvdoc/2.3.2/html/doc/tutorials/features2d/feature_detection/feature_detection.html#feature-detection
總結
以上是生活随笔為你收集整理的OpenCV 特征点检测的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: OpenCV Harris 角点检测子
- 下一篇: 朴素贝叶斯Naïve Bayes分类算法