基于特征点的图像匹配是图像处理中经常会遇到的问题,手动选取特征点太麻烦了。比较经典常用的特征点自动提取的办法有Harris特征、SIFT特征、SURF特征。
先介绍利用SURF特征的特征描述办法,其操作封装在类SurfFeatureDetector中,利用类内的detect函数可以检测出SURF特征的关键点,保存在vector容器中。第二部利用SurfDescriptorExtractor类进行特征向量的相关计算。将之前的vector变量变成向量矩阵形式保存在Mat中。最后强行匹配两幅图像的特征向量,利用了类BruteForceMatcher中的函数match。如下:
- /**
- * @file SURF_descriptor
- * @brief SURF detector + descritpor + BruteForce Matcher + drawing matches with OpenCV functions
- * @author A. Huaman
- */
- #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
- * @brief Main function
- */
- int main( int argc, char** argv )
- {
- if( argc != 3 )
- { 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 )
- { return -1; }
- //-- 步骤1:使用SURF检测器检测关键点
- int minHessian = 400;
- SurfFeatureDetector detector( minHessian );