[OpenCV] sift demo
运行环境:vs2012+opencv320
sift 需要的头文件为 <opencv2/xfeatures2d.hpp>
#include <opencv2/opencv.hpp>
#include <opencv2/xfeatures2d.hpp> using namespace cv;
using namespace std; bool refineMatchesWithHomography(
const std::vector<cv::KeyPoint>& queryKeypoints,
const std::vector<cv::KeyPoint>& trainKeypoints,
float reprojectionThreshold,
std::vector<cv::DMatch>& matches,
cv::Mat& homography)
{
const int minNumberMatchesAllowed = 8; if (matches.size() < minNumberMatchesAllowed)
return false; // Prepare data for cv::findHomography
std::vector<cv::Point2f> srcPoints(matches.size());
std::vector<cv::Point2f> dstPoints(matches.size()); for (size_t i = 0; i < matches.size(); i++) {
srcPoints[i] = trainKeypoints[matches[i].trainIdx].pt;
dstPoints[i] = queryKeypoints[matches[i].queryIdx].pt;
} // Find homography matrix and get inliers mask
std::vector<unsigned char> inliersMask(srcPoints.size());
homography = cv::findHomography(srcPoints, dstPoints, CV_FM_RANSAC,reprojectionThreshold, inliersMask); std::vector<cv::DMatch> inliers;
for (size_t i = 0; i < inliersMask.size(); i++) {
if (inliersMask[i])
inliers.push_back(matches[i]);
} matches.swap(inliers);
return matches.size() > minNumberMatchesAllowed;
} bool comp(vector<DMatch>& a,vector<DMatch>& b)
{
return a[0].distance/a[1].distance < b[0].distance/b[1].distance;
} void main()
{
Ptr<xfeatures2d::SIFT>feature=xfeatures2d::SIFT::create(); Mat input1 = imread("sift_img\\16.png",1);
Mat input2 = imread("sift_img\\11.png",1); vector<KeyPoint>kp1,kp2;
Mat des1,des2;
Mat output1,output2; feature->detectAndCompute(input1,cv::noArray(),kp1,des1);
drawKeypoints(input1,kp1,output1); feature->detectAndCompute(input2,cv::noArray(),kp2,des2);
drawKeypoints(input2,kp2,output2); vector<DMatch>matches;
vector<vector<DMatch> >Dmatches;
Ptr<cv::DescriptorMatcher> matcher_knn = new BFMatcher();
Ptr<cv::DescriptorMatcher> matcher = new BFMatcher(NORM_L2,true);
matcher->match(des1,des2,matches); matcher_knn->knnMatch(des1,des2,Dmatches,2);
sort(Dmatches.begin(),Dmatches.end(),comp); vector<DMatch> good;
for(int i=0;i<Dmatches.size();i++){
if(Dmatches[i][0].distance < 0.75*Dmatches[i][1].distance)
good.push_back(Dmatches[i][0]);
} Mat imResultOri;
drawMatches(output1, kp1, output2, kp2, matches, imResultOri,CV_RGB(0,255,0), CV_RGB(0,255,0)); Mat matHomo;
refineMatchesWithHomography(kp1, kp2, 3, matches, matHomo);
cout << "[Info] Homography T : " << endl << matHomo << endl; Mat imResult;
drawMatches(output1, kp1, output2, kp2, matches, imResult,CV_RGB(0,255,0), CV_RGB(0,255,0)); Mat Mgood;
drawMatches(output1, kp1, output2, kp2, good, Mgood,CV_RGB(0,255,0), CV_RGB(0,255,0)); imshow("ransc",imResult);
imshow("knn_match",Mgood);
waitKey(0); return;
}
[OpenCV] sift demo的更多相关文章
- VS2010+Opencv+SIFT以及出现的问题-关于代码sift_3_c的说明
http://blog.sina.com.cn/s/blog_a6b913e30101dvrt.html 一.前提 安装Opencv,因该版本的SIFT是基于Opencv的. 下载SIFT源码,见Ro ...
- RPi 2B python opencv camera demo example
/************************************************************************************** * RPi 2B pyt ...
- Opencv Sift算子特征提取与匹配
SIFT算法的过程实质是在不同尺度空间上查找特征点(关键点),用128维方向向量的方式对特征点进行描述,最后通过对比描述向量实现目标匹配. 概括起来主要有三大步骤: 1.提取关键点: 2.对关键点附加 ...
- OpenCV SIFT原理与源码分析
http://blog.csdn.net/xiaowei_cqu/article/details/8069548 SIFT简介 Scale Invariant Feature Transform,尺度 ...
- python opencv SIFT,获取特征点的坐标位置
备注:SIFT算法的实质是在不同的尺度空间上查找关键点(特征点),并计算出关键点的方向.SIFT所查找到的关键点是一些十分突出,不会因光照,仿射变换和噪音等因素而变化的点,如角点.边缘点.暗区的亮点及 ...
- OpenCV——SIFT特征检测与匹配
SIFT特征和SURF特征比较 比较项目 SIFT SURF 尺度空间极值检测 使用高斯滤波器,根据不同尺度的高斯差(DOG)图像寻找局部极值 使用方形滤波器,利用海森矩阵的行列式值检测极值,并利用积 ...
- Opencv Sift和Surf特征实现图像无缝拼接生成全景图像
Sift和Surf算法实现两幅图像拼接的过程是一样的,主要分为4大部分: 1. 特征点提取和描述 2. 特征点配对,找到两幅图像中匹配点的位置 3. 通过配对点,生成变换矩阵,并对图像1应用变换矩阵生 ...
- opencv::sift特征提取
SIFT特征检测介绍 SIFT(Scale-Invariant Feature Transform)特征检测关键特性: -建立尺度空间,寻找极值 -关键点定位(寻找关键点准确位置与删除弱边缘) -关键 ...
- python+opencv+sift环境配置教程
最近在做对应点估计homography,需要用到opencv,c++的接口不如python的接口来的方便 但是在安装python接口的opencv的时候,遇到了各种问题,主要是函数找不到的问题 比如在 ...
随机推荐
- Codeforces Round #583 (Div. 1 + Div. 2, based on Olympiad of Metropolises) A题
A. Optimal Currency ExchangeAndrew was very excited to participate in Olympiad of Metropolises. Days ...
- 020_linux驱动之_输入子系统按键应用
(一)分配一个输入子系统结构体 static struct input_dev *buttons_dev; /*分配一个input_dev结构体*/ (二)设置这个输入子系统需要的动作 /* 1. 分 ...
- 线程的分离状态 detached joinable
转自 http://blog.chinaunix.net/uid-26983585-id-3315953.html 其实在写上一篇日志的时候,由于我把创建线程的返回值的判断条件写错了,程序每次运行的 ...
- MySQl的库操作、表操作和数据操作
一.库操作 1.1库的增删改查 (1)系统数据库: performance_schema:用来收集数据库服务器的性能参数,记录处理查询时发生的各种事件.锁等现象 mysql:授权库,主要存储系统用户的 ...
- python输出的高亮显示
一.语法 1.书写格式 开头部分: \033[显示方式;前景色;背景色m 结尾部分: \033[0m 例如:\033[31;1m测试的文字部分\033[0m 注意: 开头部分的三个参数:显示方 ...
- iTerm2 半透明颜色主题与字体配置
下载iTerm2https://www.iterm2.com/ 安装. 下载这个主题https://raw.githubusercontent.com/mbadolato/iTerm2-Color-S ...
- ie中打印的问题
一般正常的情况下使用window.print();各个浏览器都可以调用出打印功能来但是ie有个坑就是如果页面在iframe里的话打印出来就是错的页面所以在这里要这样写: var agent = nav ...
- Echarts案例-折线图
一:先在官网下载 https://www.echartsjs.com/zh/download.html 然后再建立工程,导入这两个包: 写代码: <!DOCTYPE html> <h ...
- TCP SACK 介绍 转载
一.SACK选项 默认情况下TCP采取的是累积确认机制,这时如果发生了报文乱序到达,接收方只会重复确认最后一个按序到达的报文段,为此发送方的处理只能是重复按序到达接收方的报文段之后的那个报文段,因而它 ...
- redhat7.4安装git(按照官网从源码安装)
按照官方文档建议使用源码安装 1.为什么不用yum安装 yum安装确实简单,只用一行命令就可以了,但是yum安装的版本太低. //安装前使用info查看git版本信息等 yum info git yu ...