3. opencv进行SIFT特征提取
opencv中sift特征提取的步骤
- 使用SiftFeatureDetector的detect方法检测特征存入一个向量里,并使用drawKeypoints在图中标识出来
- SiftDescriptorExtractor 的compute方法提取特征描述符,特征描述符是一个矩阵
- 使用匹配器matcher对描述符进行匹配,匹配结果保存由DMatch的组成的向量里
- 设置距离阈值,使得匹配的向量距离小于最小距离的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特征提取的更多相关文章
- [转]SIFT特征提取分析
SIFT(Scale-invariant feature transform)是一种检测局部特征的算法,该算法通过求一幅图中的特征点(interest points,or corner points) ...
- SIFT特征提取分析
SIFT特征提取分析 sift 关键点,关键点检测 读'D. G. Lowe. Distinctive Image Features from Scale-Invariant Keypoints[J] ...
- java 在centos6.5+eclipse环境下调用opencv实现sift算法
java 在centos6.5+eclipse环境下调用opencv实现sift算法,代码如下: import org.opencv.core.Core; import org.opencv.core ...
- OPENCV下SIFT算法使用方法笔记
这几天继续在看Lowe大神的SIFT神作,看的眼花手脚抽筋.也是醉了!!!!实在看不下去,来点干货.我们知道opencv下自带SIFT特征检测以及MATCH匹配的库,这些库完全可以让我们进行傻瓜似的操 ...
- OpenCV实现SIFT图像拼接源代码
OpenCV实现SIFT和KDtree和RANSAC图像拼接源代码,此源代码由Opencv2.4.13.6和VC++实现,代码本人已经调试过,完美运行,效果如附图.Opencv2.4.13.6下载地址 ...
- opencv::sift特征提取
SIFT特征检测介绍 SIFT(Scale-Invariant Feature Transform)特征检测关键特性: -建立尺度空间,寻找极值 -关键点定位(寻找关键点准确位置与删除弱边缘) -关键 ...
- SIFT特征提取分析(转载)
转载自: http://blog.csdn.net/abcjennifer/article/details/7639681 SIFT(Scale-invariant feature transform ...
- [OpenCV-Python] OpenCV 中图像特征提取与描述 部分 V (一)
部分 V图像特征提取与描述 OpenCV-Python 中文教程(搬运)目录 29 理解图像特征 目标本节我会试着帮你理解什么是图像特征,为什么图像特征很重要,为什么角点很重要等.29.1 解释 我相 ...
- [OpenCV-Python] OpenCV 中图像特征提取与描述 部分 V (二)
部分 V图像特征提取与描述 OpenCV-Python 中文教程(搬运)目录 34 角点检测的 FAST 算法 目标 • 理解 FAST 算法的基础 • 使用 OpenCV 中的 FAST 算法相关函 ...
随机推荐
- 【Python千问 1】Python核心编程(第二版)导读
第一章 欢迎来到Python世界 什么是Python Python的起源 Python的特点 下载Python 安装Python 运行Python Python文档 比较Python(与其它语言的比较 ...
- Hosts文件是什么?
Hosts文件主要作用是定义IP地址和主机名的映射关系,是一个映射IP地址和主机名的规定.可以用文本文件打开!当用户在浏览器中输入一个需要登录的 网址时,系统会首先自动从Hosts文件中寻找对应的IP ...
- 《MFC游戏开发》笔记五 定时器和简单动画
本系列文章由七十一雾央编写,转载请注明出处. http://blog.csdn.net/u011371356/article/details/9332377 作者:七十一雾央 新浪微博:http:// ...
- mybatis--MapperProxy事务
上篇 详细分析了org.mybatis.spring.mapper.MapperScannerConfigurer 和 org.mybatis.spring.SqlSessionFactoryBean ...
- DNS的递归查询和迭代查询
百度运维部二面,直接懵逼的节奏 (1)递归查询 递归查询是一种DNS 服务器的查询模式,在该模式下DNS 服务器接收到客户机请求, 必须使用一个准确的查询结果回复客户机. 如果DNS 服务器本地没有存 ...
- codeforces 677A A. Vanya and Fence(水题)
题目链接: A. Vanya and Fence time limit per test 1 second memory limit per test 256 megabytes input stan ...
- 微信(一) 获取openid 网页授权 C# WeChatHelper
用.Net开发微信的时候第一步就是获取微信的网页授权,获取openid. 自己做个总结,以后也好用,这里只提供了获取openid的接口,后续程序有待开发 using System; using Sys ...
- WCF之安全
传输安全. 点对点,对整个消息进行加密,性能损失,当中间者不安全时,消息也就不安全了. WCF中支持传输安全和消息安全模式. 通过配置和绑定来设置.<Security Mode =Transct ...
- WCF之错误和异常
CLR异常无法跨越服务边界,所有的异常都被封装(序列化)为SOAP Fault,可以让所有平台的用户接收到. SOAP1.1只有Body.1.2中含有Header+Body. 未捕获异常 异常会从逻辑 ...
- 9个超绚丽的HTML5 3D图片动画特效
在Web 1.0时代,我们的网页中图片数量非常少,而且都是以静态图片为主.HTML5的出现,推动了Web 2.0的发展,同时也催生出了很多绚丽的HTML5图片动画特效,特别是有些还有3D的动画效果.本 ...