opencv学习之路(35)、SURF特征点提取与匹配(三)
一、简介



二、opencv中的SURF算法接口

三、特征点匹配方法

四、代码
1.特征点提取
#include "opencv2/opencv.hpp"
#include <opencv2/nonfree/nonfree.hpp>
#include <vector>
#include<iostream>
using namespace std;
using namespace cv; void main()
{
Mat srcImg1 = imread("E://1.jpg");
Mat srcImg2 = imread("E://2.jpg");
//定义SURF特征检测类对象
SurfFeatureDetector surfDetector();//SIFT有默认值,SURF没有默认值,需要赋初值 hessianThreshold
//定义KeyPoint变量
vector<KeyPoint>keyPoints1;
vector<KeyPoint>keyPoints2;
//特征点检测
surfDetector.detect(srcImg1, keyPoints1);
surfDetector.detect(srcImg2, keyPoints2);
//绘制特征点(关键点)
Mat feature_pic1, feature_pic2;
drawKeypoints(srcImg1, keyPoints1, feature_pic1, Scalar(,,));
//drawKeypoints(srcImg2, keyPoints2, feature_pic2, Scalar::all(-1));
//drawKeypoints(srcImg1, keyPoints1, feature_pic1, Scalar::all(-1), DrawMatchesFlags::DRAW_RICH_KEYPOINTS);
drawKeypoints(srcImg2, keyPoints2, feature_pic2, Scalar::all(-), DrawMatchesFlags::DRAW_RICH_KEYPOINTS);
//显示原图
imshow("src1", srcImg1);
imshow("src2", srcImg2);
//显示结果
imshow("feature1", feature_pic1);
imshow("feature2", feature_pic2); waitKey();
}

2.暴力匹配(尽量避免使用“nth_element前多少个”筛选)
#include "opencv2/opencv.hpp"
#include <opencv2/nonfree/nonfree.hpp>
#include <opencv2/legacy/legacy.hpp>
#include <vector>
#include<iostream>
using namespace std;
using namespace cv; void main()
{
Mat srcImg1 = imread("E://11.jpg");
Mat srcImg2 = imread("E://22.jpg");
//定义SURF特征检测类对象
SurfFeatureDetector surfDetector(); //HessianThreshold //定义KeyPoint变量
vector<KeyPoint>keyPoints1;
vector<KeyPoint>keyPoints2;
//特征点检测
surfDetector.detect(srcImg1, keyPoints1);
surfDetector.detect(srcImg2, keyPoints2);
//绘制特征点(关键点)
Mat feature_pic1, feature_pic2;
drawKeypoints(srcImg1, keyPoints1, feature_pic1, Scalar::all(-));
drawKeypoints(srcImg2, keyPoints2, feature_pic2, Scalar::all(-));
//显示原图
imshow("src1", srcImg1);
imshow("src2", srcImg2);
//显示结果
imshow("feature1", feature_pic1);
imshow("feature2", feature_pic2); //计算特征点描述符 / 特征向量提取
SurfDescriptorExtractor descriptor;
Mat description1;
descriptor.compute(srcImg1, keyPoints1, description1);
Mat description2;
descriptor.compute(srcImg2, keyPoints2, description2);
cout<<description1.cols<<endl;
cout<<description1.rows<<endl; //进行BFMatch暴力匹配
BruteForceMatcher<L2<float>>matcher; //实例化暴力匹配器
vector<DMatch>matches; //定义匹配结果变量
matcher.match(description1, description2, matches); //实现描述符之间的匹配 //计算向量距离的最大值与最小值
double max_dist=, min_dist=;
for(int i=; i<description1.rows; i++)
{
if(matches.at(i).distance > max_dist)
max_dist = matches[i].distance;
if(matches.at(i).distance < min_dist)
min_dist = matches[i].distance;
}
cout<<"min_distance="<<min_dist<<endl;
cout<<"max_distance="<<max_dist<<endl; //匹配结果筛选
vector<DMatch>good_matches;
for(int i=; i<matches.size(); i++)
{
if(matches[i].distance < *min_dist)
good_matches.push_back(matches[i]);
} Mat result;
//drawMatches(srcImg1, keyPoints1, srcImg2, keyPoints2, matches, result, Scalar::all(-1), Scalar::all(-1));
drawMatches(srcImg1, keyPoints1, srcImg2, keyPoints2, good_matches, result, Scalar(, , ), Scalar::all(-));
imshow("Match_Result", result); waitKey();
}

因为surf检测到的角点比较少,所以不适合做小目标匹配。
同样代码,使用sift作对比

3.FlannBasedMatcher匹配
//BruteForceMatcher<L2<float>>matcher; //实例化暴力匹配器
FlannBasedMatcher matcher; //实例化FLANN匹配器
vector<DMatch>matches; //定义匹配结果变量
matcher.match(description1, description2, matches); //实现描述符之间的匹配
其余代码相同
opencv学习之路(35)、SURF特征点提取与匹配(三)的更多相关文章
- OpenCV成长之路(9):特征点检测与图像匹配
特征点又称兴趣点.关键点,它是在图像中突出且具有代表意义的一些点,通过这些点我们可以用来识别图像.进行图像配准.进行3D重建等.本文主要介绍OpenCV中几种定位与表示关键点的函数. 一.Harris ...
- Opencv学习之路—Opencv下基于HOG特征的KNN算法分类训练
在计算机视觉研究当中,HOG算法和LBP算法算是基础算法,但是却十分重要.后期很多图像特征提取的算法都是基于HOG和LBP,所以了解和掌握HOG,是学习计算机视觉的前提和基础. HOG算法的原理很多资 ...
- opencv学习之路(34)、SIFT特征匹配(二)
一.特征匹配简介 二.暴力匹配 1.nth_element筛选 #include "opencv2/opencv.hpp" #include <opencv2/nonfree ...
- opencv学习之路(33)、SIFT特征点提取(一)
一.简介 二.OpenCV中的SIFT算法接口 #include "opencv2/opencv.hpp" #include <opencv2/nonfree/nonfree ...
- opencv学习之路(19)、直方图
一.概述 二.一维灰度直方图 #include "opencv2/opencv.hpp" #include<iostream> using namespace cv; ...
- opencv学习之路(41)、人脸识别
一.人脸检测并采集个人图像 //take_photo.cpp #include<opencv2/opencv.hpp> using namespace cv; using namespac ...
- opencv学习之路(40)、人脸识别算法——EigenFace、FisherFace、LBPH
一.人脸识别算法之特征脸方法(Eigenface) 1.原理介绍及数据收集 特征脸方法主要是基于PCA降维实现. 详细介绍和主要思想可以参考 http://blog.csdn.net/u0100066 ...
- opencv学习之路(20)、直方图应用
一.直方图均衡化--equalizeHist() #include "opencv2/opencv.hpp" using namespace cv; void main() { 6 ...
- opencv学习之路(18)、霍夫变换
一.简介 在图像处理和计算机视觉领域中,如何从当前的图像中提取所需要的特征信息是图像识别的关键所在.在许多应用场合中需要快速准确地检测出直线或者圆.其中一种非常有效的解决问题的方法是霍夫(Hough) ...
随机推荐
- C++标准库algorithm
(1) 基本数学相关: max(t1, t2)和min(t1, t2), 返回t1和t2中的较大.较小者. max_element(b, e)和min_element(b, e), 返回两个迭代器所指 ...
- Overview of Azure Storage
Azure Storage types Blob storage. Containers for data blobs. The three types of blobs are: Page blob ...
- maven jdk版本
http://maven.apache.org/docs/history.html Maven Releases History Date format is: YYYY-MM-DD Maven 3 ...
- 【转】tars源码漫谈第1篇------tc_loki.h (牛逼哄哄的loki库)
loki库是C++模板大牛Andrei写的, 里面大量运用模板的特性, 而tc_loki.h借用了loki库的部分代码, 形成了一个基本的文件tc_loki.h, 来看看: #ifndef __TC_ ...
- 2018年年度总结 & 2019年计划
2018关键词 「探索」 引用以前作文最爱写的开头,时间如白驹过隙,回想上次写17年年度总结,仿佛也就过了几日光景. 首先回顾一下17年定下的目标, 18年我将关键字设为探索,目的有两个,一是 ...
- vueX、vue中transition的使用、axios
引入一篇好文章链接:看一遍就会的vuex文章;完!!! vue中transtion的使用:transition文章;完!!! axios的文章:axios;完!!!
- es6下 vue实例属性template不能使用
esm模式下 不能使用template,需要引入非esm的vue.js,查看vue源码的包的dist目录下 文件标有esm是支持ems,没有标记,就是不支持(这个知识,怎么说了,应该属于webpack ...
- 模拟网络状况工具——clumsy
官网:http://jagt.github.io/clumsy/index.html 官网上的介绍已经很易懂了,所以本文只是直接翻译了官网内容. clumsy 能在 Windows 平台下人工造成不稳 ...
- Charles 的界面详解
后续补充.......... 一.主导航栏 1.File.Edit.View.Proxy.Tools.Window.Help 2.View栏 (1)structure视图是将网络请求按访问的域名分类: ...
- git reset与git revert的区别
http://alpha-blog.wanglianghome.org/2010/07/30/git-partial-rollback/ reset(版本撤回) 格式 git reset [-q] [ ...