[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的时候,遇到了各种问题,主要是函数找不到的问题 比如在 ...
随机推荐
- Appium自动化测试教程-自学网-SDK
SDK:软件开发工具包,被软件开发工程师用于特定的软件包.软件框架.硬件平台.操作系统等建立应用软件的开发工具的集合. 因此,Android SDK指的是Android专属的软件开发工具包. 1,安装 ...
- UVA1426 Discrete Square Roots
思路:\(exgcd\) 提交:\(2\)次 错因:输出格式错误OTZ 题解: 求:\(r^2 ≡ x \mod N , 0 \leq r < N\),并且题目会给出 \(x,N\) 和一个合法 ...
- PHP mysqli_connect() 函数
打开一个到 MySQL 服务器的新的连接: mysqli_connect(host,username,password,dbname,port,socket); <?php $con=mysql ...
- 007_Linux驱动之_copy_from_user函数
1. copy_from_user函数的目的是从用户空间拷贝数据到内核空间 2. 解析原型: copy_from_user(void *to, const void __user *from, uns ...
- [Luogu] 魔板
https://www.luogu.org/problemnew/show/P1275 #include <iostream> #include <cstdio> #inclu ...
- 【csp模拟赛3】bridge.cpp--矩阵加速递推
题目描述 穿越了森林,前方有一座独木桥,连接着过往和未来(连接着上一题和下一题...). 这座桥无限长. 小 Q 在独木桥上彷徨了.他知道,他只剩下了 N 秒的时间,每一秒的时间里,他会向 左或向右移 ...
- 2016百度之星资格赛 Problem B(大数+组合数)
题意:度熊面前有一个全是由1构成的字符串,被称为全1序列.你可以合并任意相邻的两个1,从而形成一个新的序列.对于给定的一个全1序列,请计算根据以上方法,可以构成多少种不同的序列.最多200个1. 比如 ...
- Flutter实现TabBarView切换页面时每个页面只initState一次
在 TabBarView 组件中切换页面时,子页面每次均会重新 initState 一次,导致每次都切换页面均会重绘,如下图 如果需要只在第一次进页面 initState 一次,后面再进入 ...
- Geth安装和使用
版权声明:本文为博主原创文章,未经博主允许不得转载. https://blog.csdn.net/u011680118/article/details/82378509 一.简介 Geth是Go ...
- jmeter连接oracle数据库
== 下载及添加这个文件到 这个路径下 连接设置: 测试连接 链接: https://pan.baidu.com/s/1W0YcVf4VLdsjnxv5umKngQ 提取码: np7j