opencv中sift特征提取的步骤

  1. 使用SiftFeatureDetector的detect方法检测特征存入一个向量里,并使用drawKeypoints在图中标识出来
  2. SiftDescriptorExtractor 的compute方法提取特征描述符,特征描述符是一个矩阵
  3. 使用匹配器matcher对描述符进行匹配,匹配结果保存由DMatch的组成的向量里
  4. 设置距离阈值,使得匹配的向量距离小于最小距离的2被才能进入最终的结果,用DrawMatch可以显示

代码

// 使用Flann进行特征点匹配.cpp : 定义控制台应用程序的入口点。
//
#include "stdafx.h"
#include <opencv2/opencv.hpp>
#include <highgui/highgui.hpp>
#include <features2d/features2d.hpp>
#include <nonfree/nonfree.hpp>
#include <vector>
using namespace cv;
using namespace std;
int _tmain(int argc, _TCHAR* argv[])
{
Mat input1 = imread("E://code//test//image//box.png", 1);
Mat input2 = imread("E://code//test//image//box_in_scene.jpg", 1);
if (input1.empty()||input2.empty())
{
cout << "不能正常加载图片" << endl;
system("pause");
return -1;
}
/************************************************************************/
/*下面进行提取特征点*/
/************************************************************************/
SiftFeatureDetector feature;
vector<KeyPoint> kerpoints1;
feature.detect(input1, kerpoints1);
Mat output1;
drawKeypoints(input1, kerpoints1, output1);
vector<KeyPoint> kerpoints2;
feature.detect(input2, kerpoints2);
Mat output2;
drawKeypoints(input2, kerpoints2, output2);
imshow("提取特征点后的box.png", output1);
imshow("提取特征点后的box_in_scene.png", output2);
imwrite("提取特征点后的box.png", output1);
imwrite("提取特征点后的box_in_scene.png", output2);
cout << "box提取的特征点数为:" << kerpoints1.size() << endl;
cout << "box_in_scene的特征点数为:" << kerpoints2.size() << endl;
/************************************************************************/
/* 下面进行特征向量提取 */
/************************************************************************/
SiftDescriptorExtractor descript;
Mat description1;
descript.compute(input1, kerpoints1, description1);
Mat description2;
descript.compute(input2, kerpoints2, description2);
/************************************************************************/
/* 下面进行特征向量临近匹配 */
/************************************************************************/
vector<DMatch> matches;
FlannBasedMatcher matcher;
Mat image_match;
matcher.match(description1, description2, matches);
/************************************************************************/
/* 下面计算向量距离的最大值与最小值 */
/************************************************************************/
double max_dist = 0, min_dist = 100;
for (int i = 0; i < description1.rows; i++)
{
if (matches.at(i).distance>max_dist)
{
max_dist = matches[i].distance;
}
if (matches[i].distance<min_dist)
{
min_dist = matches[i].distance;
}
}
cout << "最小距离为" << min_dist << endl;
cout << "最大距离为" << max_dist << endl;
/************************************************************************/
/* 得到距离小于而V诶最小距离的匹配 */
/************************************************************************/
vector<DMatch> good_matches;
for (int i = 0; i < matches.size(); i++)
{
if (matches[i].distance<2*min_dist)
{
good_matches.push_back(matches[i]);
cout <<"第一个图中的"<< matches[i].queryIdx<<"匹配了第二个图中的"<<matches[i].trainIdx<<endl;
}
}
drawMatches(input1, kerpoints1, input2, kerpoints2, good_matches, image_match);
imshow("匹配后的图片", image_match);
imwrite("匹配后的图片.png", image_match);
cout << "匹配的特征点数为:" << good_matches.size() << endl;
waitKey(0);
return 0;
}

程序运行前的原始图片



提取特征点后



进行匹配后

相关代码介绍

    double max_dist = 0, min_dist = 100;
for (int i = 0; i < description1.rows; i++)
{
if (matches.at(i).distance>max_dist)
{
max_dist = matches[i].distance;
}
if (matches[i].distance<min_dist)
{
min_dist = matches[i].distance;
}
}

设置阈值,当特征向量的距离在最小距离的二倍范围内的,匹配为好的匹配;

本博文由时尚时尚最时尚的markdown编辑器编写.

3. opencv进行SIFT特征提取的更多相关文章

  1. [转]SIFT特征提取分析

    SIFT(Scale-invariant feature transform)是一种检测局部特征的算法,该算法通过求一幅图中的特征点(interest points,or corner points) ...

  2. SIFT特征提取分析

    SIFT特征提取分析 sift 关键点,关键点检测 读'D. G. Lowe. Distinctive Image Features from Scale-Invariant Keypoints[J] ...

  3. java 在centos6.5+eclipse环境下调用opencv实现sift算法

    java 在centos6.5+eclipse环境下调用opencv实现sift算法,代码如下: import org.opencv.core.Core; import org.opencv.core ...

  4. OPENCV下SIFT算法使用方法笔记

    这几天继续在看Lowe大神的SIFT神作,看的眼花手脚抽筋.也是醉了!!!!实在看不下去,来点干货.我们知道opencv下自带SIFT特征检测以及MATCH匹配的库,这些库完全可以让我们进行傻瓜似的操 ...

  5. OpenCV实现SIFT图像拼接源代码

    OpenCV实现SIFT和KDtree和RANSAC图像拼接源代码,此源代码由Opencv2.4.13.6和VC++实现,代码本人已经调试过,完美运行,效果如附图.Opencv2.4.13.6下载地址 ...

  6. opencv::sift特征提取

    SIFT特征检测介绍 SIFT(Scale-Invariant Feature Transform)特征检测关键特性: -建立尺度空间,寻找极值 -关键点定位(寻找关键点准确位置与删除弱边缘) -关键 ...

  7. SIFT特征提取分析(转载)

    转载自: http://blog.csdn.net/abcjennifer/article/details/7639681 SIFT(Scale-invariant feature transform ...

  8. [OpenCV-Python] OpenCV 中图像特征提取与描述 部分 V (一)

    部分 V图像特征提取与描述 OpenCV-Python 中文教程(搬运)目录 29 理解图像特征 目标本节我会试着帮你理解什么是图像特征,为什么图像特征很重要,为什么角点很重要等.29.1 解释 我相 ...

  9. [OpenCV-Python] OpenCV 中图像特征提取与描述 部分 V (二)

    部分 V图像特征提取与描述 OpenCV-Python 中文教程(搬运)目录 34 角点检测的 FAST 算法 目标 • 理解 FAST 算法的基础 • 使用 OpenCV 中的 FAST 算法相关函 ...

随机推荐

  1. Pull解析-解析xml文件

    首先需要导入jar包:kxml2-2.2.2.jar 例程: main: /** * pull解析 * * @author my * */ public class DemoParserStudent ...

  2. oracle使用pfile或者spfile启动

    oracle 11G使用pfile启动数据库 startup pfile='pfile参数文件路径' oracle 11G使用spfile启动数据库 spfile=Windows缺省目录    %OR ...

  3. 启动 Eclipse 弹出“Failed to load the JNI shared library jvm.dll”错误的解决方法!&&在eclipse.ini中为eclipse指定jdk启动

    参考:http://blog.csdn.net/zyz511919766/article/details/7442633 http://blog.sina.com.cn/s/blog_028f0c1c ...

  4. hdu-5700 区间交(二分+树状数组)

    题目链接: 区间交 Problem Description   小A有一个含有n个非负整数的数列与mm个区间.每个区间可以表示为l​i​​,r​i​​. 它想选择其中k个区间, 使得这些区间的交的那些 ...

  5. JQuery Validate验证显示错误提示位置

    验证多个Name值相同的元素: $(".send").click(function () { var a = 0; var b = 0; var c = 0; var d = 0; ...

  6. WPF ScrollViewer(滚动条) 自定义样式表制作 再发一套样式 细节优化

    艾尼路 出的效果图 本人嵌套 WPF ScrollViewer(滚动条) 自定义样式表制作 图文并茂 WPF ScrollViewer(滚动条) 自定义样式表制作 (改良+美化) 源代码

  7. Table of Contents - Lombok

    Installation Lombok Annotations @Getter, @Setter, @ToString, @EqualsAndHashCode & @Data @NoArgsC ...

  8. 安装sybase12.0,运行时报错异常。

    报错为:invalid command line argument ' and' 当通过开始菜单打开"配置服务器"时,回报如上异常,当继续创建服务器是,不会成功.实际上不是程序出错 ...

  9. NodeJs多进程和socket.io通讯-DEMO

    一.开启多进程 const os = require('os'); const cp = require('child_process'); const forkList = {}; const fo ...

  10. jquery页面滚动,菜单固定到顶部

    // 菜单固定 $(function(){ //获取要定位元素距离浏览器顶部的距离 var navH = $("#topp").offset().top; //滚动条事件 $(wi ...