OpenCV中feature2D学习——FAST特征点检测与SIFT/SURF/BRIEF特征提取与匹配
来源:互联网 发布:淘宝店面装修多少钱 编辑:程序博客网 时间:2024/06/02 11:34
在前面的文章《OpenCV中feature2D学习——FAST特征点检测》中讲了利用FAST算子进行特征点检测,这里尝试使用FAST算子来进行特征点检测,并结合SIFT/SURF/BRIEF算子进行特征点提取和匹配。
I、结合SIFT算子进行特征点提取和匹配
由于数据类型的不同,SIFT和SURF算子只能采用FlannBasedMatcher或者BruteForceMatcher来进行匹配(参考OpenCV中feature2D学习——BFMatcher和FlannBasedMatcher)。
/*** @概述:采用FAST算子检测特征点,采用SIFT算子对特征点进行特征提取,并使用BruteForce匹配法进行特征点的匹配* @类和函数:FastFeatureDetector + SiftDescriptorExtractor + BruteForceMatcher* @author:holybin*/#include <stdio.h>#include <iostream>#include "opencv2/core/core.hpp"#include "opencv2/nonfree/features2d.hpp"//SurfFeatureDetector实际在该头文件中#include "opencv2/legacy/legacy.hpp"//BruteForceMatcher实际在该头文件中//#include "opencv2/features2d/features2d.hpp"//FlannBasedMatcher实际在该头文件中#include "opencv2/highgui/highgui.hpp"using namespace cv;using namespace std;int main( int argc, char** argv ){Mat src_1 = imread("cat3d120.jpg");Mat src_2 = imread("cat0.jpg");if( !src_1.data || !src_2.data ){ cout<< " --(!) Error reading images "<<endl;return -1; }//-- Step 1: 使用FAST算子检测特征点FastFeatureDetector fast(20);vector<KeyPoint> keypoints_1, keypoints_2;fast.detect( src_1, keypoints_1 );//FAST(src_1, keypoints_1, 20); fast.detect( src_2, keypoints_2 );//FAST(src_2, keypoints_2, 20); cout<<"img1--number of keypoints: "<<keypoints_1.size()<<endl;cout<<"img2--number of keypoints: "<<keypoints_2.size()<<endl;//-- Step 2: 使用SIFT算子提取特征(计算特征向量)SiftDescriptorExtractor extractor;//SurfDescriptorExtractor extractor;Mat descriptors_1, descriptors_2;extractor.compute( src_1, keypoints_1, descriptors_1 );extractor.compute( src_2, keypoints_2, descriptors_2 );//-- Step 3: 使用BruteForce法进行暴力匹配BruteForceMatcher< L2<float> > matcher;//FlannBasedMatcher matcher;vector< DMatch > matches;matcher.match( descriptors_1, descriptors_2, matches );cout<<"number of matches: "<<matches.size()<<endl;//-- 显示匹配结果Mat matchImg;drawMatches( src_1, keypoints_1, src_2, keypoints_2, matches, matchImg,Scalar::all(-1), Scalar::all(-1), vector<char>(), DrawMatchesFlags::NOT_DRAW_SINGLE_POINTS); imshow("matching result", matchImg );imwrite("match_result.png", matchImg);waitKey(0);return 0;}
运行结果如下:
II、结合BRIEF算子进行特征点提取和匹配
BRIEF算子只能采用BruteForceMatcher来进行匹配(参考OpenCV中feature2D学习——BFMatcher和FlannBasedMatcher)。
/*** @概述:采用FAST算子检测特征点,采用BRIEF算子对特征点进行特征提取,并使用BruteForce匹配法进行特征点的匹配* @类和函数:FastFeatureDetector + BriefDescriptorExtractor + BruteForceMatcher* @author:holybin*/#include <stdio.h>#include <iostream>#include "opencv2/core/core.hpp"#include "opencv2/nonfree/features2d.hpp"//SurfFeatureDetector实际在该头文件中#include "opencv2/legacy/legacy.hpp"//BruteForceMatcher实际在该头文件中//#include "opencv2/features2d/features2d.hpp"//FlannBasedMatcher实际在该头文件中#include "opencv2/highgui/highgui.hpp"using namespace cv;using namespace std;int main( int argc, char** argv ){Mat src_1 = imread("cat3d120.jpg");Mat src_2 = imread("cat0.jpg");if( !src_1.data || !src_2.data ){ cout<< " --(!) Error reading images "<<endl;return -1; }//-- Step 1: 使用FAST算子检测特征点FastFeatureDetector fast(20);vector<KeyPoint> keypoints_1, keypoints_2;fast.detect( src_1, keypoints_1 );//FAST(src_1, keypoints_1, 20); fast.detect( src_2, keypoints_2 );//FAST(src_2, keypoints_2, 20); cout<<"img1--number of keypoints: "<<keypoints_1.size()<<endl;cout<<"img2--number of keypoints: "<<keypoints_2.size()<<endl;//-- Step 2: 使用BRIEF算子提取特征(计算特征向量)BriefDescriptorExtractor extractor;Mat descriptors_1, descriptors_2;extractor.compute( src_1, keypoints_1, descriptors_1 );extractor.compute( src_2, keypoints_2, descriptors_2 );//-- Step 3: 使用BruteForce法进行暴力匹配BruteForceMatcher< L2<float> > matcher;//FlannBasedMatcher matcher;vector< DMatch > matches;matcher.match( descriptors_1, descriptors_2, matches );cout<<"number of matches: "<<matches.size()<<endl;//-- 显示匹配结果Mat matchImg;drawMatches( src_1, keypoints_1, src_2, keypoints_2, matches, matchImg,Scalar::all(-1), Scalar::all(-1), vector<char>(), DrawMatchesFlags::NOT_DRAW_SINGLE_POINTS); imshow("matching result", matchImg );imwrite("match_result.png", matchImg);waitKey(0);return 0;}
运行结果如下:
0 0
- OpenCV中feature2D学习——FAST特征点检测与SIFT/SURF/BRIEF特征提取与匹配
- OpenCV中feature2D学习——SIFT和SURF算子实现特征点提取与匹配
- OpenCV中feature2D学习——SIFT和SURF算子实现特征点提取与匹配
- OpenCV中feature2D学习——SURF和SIFT算子实现特征点检测
- OpenCV中feature2D学习——SURF和SIFT算子实现特征点检测
- OpenCV中feature2D学习——FAST特征点检测
- 【OpenCV学习笔记】三十七、特征检测与匹配(二)——SIFT特征点匹配
- 【OpenCV学习笔记】三十八、特征检测与匹配(三)——SURF特征点检测与匹配
- 学习OpenCV——Fast检测与Surf&Brief匹配(娱乐)
- 学习OpenCV——Fast检测与Surf&Brief匹配(娱乐)
- opencv(30)---特征检测与匹配(1)---SIFT特征点提取
- 【opencv】特征点检测方法--GFTT,SIFT,FAST,SURF
- 【opencv】特征点检测方法--GFTT,SIFT,FAST,SURF
- opencv 特征点提取算法 SIFT SURF ORB FAST LBP学习(一)
- opencv 特征点提取算法 SIFT SURF ORB FAST LBP学习(二)
- OpenCV中特征检测,提取与匹配使用方法学习
- OpenCV中特征检测,提取与匹配使用方法学习
- Surf特征点检测与匹配
- js父页面如何通过子页面查询后回填到父页面的input框中去
- java中静态方法和非静态方法的存储
- xmlns:android作用以及自定义布局属性
- Android JavaScript调用Java 方法
- Razor输出字符串和变量
- OpenCV中feature2D学习——FAST特征点检测与SIFT/SURF/BRIEF特征提取与匹配
- Medoo入门:安装和配置-Medoo使用指南
- Android 国内集成使用谷歌地图
- 【C++基础之十】友元函数和友元类
- BAT及各大互联网公司2014前端笔试面试题--Html,Css篇
- OkHttp 2.0
- android应用程序如何调用支付宝接口
- MyEclipse安装插件的几种方法
- 求二叉树第k层节点个数