#include <iostream>
#include <string>
#include <boost/timer.hpp>
#include "opencv2/core/core.hpp"
#include "opencv2/features2d/features2d.hpp"
#include "opencv2/highgui/highgui.hpp"
#include "opencv2/flann/flann.hpp" using namespace std;
using namespace cv; void readme();
string type2str(int type); int main( int argc, char** argv )
{
if( argc != )
{
readme();
return -;
} Mat img_1 = imread( argv[], CV_LOAD_IMAGE_GRAYSCALE );
Mat img_2 = imread( argv[], CV_LOAD_IMAGE_GRAYSCALE ); if( !img_1.data || !img_2.data )
{
cout<< " --(!) Error reading images " << endl;
return -;
} //-- Step 1: Detect the keypoints using ORB Detector cv::Ptr<cv::ORB> orb = cv::ORB::create(); std::vector<KeyPoint> keypoints_1, keypoints_2; orb->detect( img_1, keypoints_1 );
orb->detect( img_2, keypoints_2 );
//-- Step 2: Calculate descriptors (feature vectors) Mat descriptors_1, descriptors_2; // descriptor is a cv::Mat, with rows the same as nFeatures, and cols as 32 (8UC1)
orb->compute( img_1, keypoints_1, descriptors_1 );
orb->compute( img_2, keypoints_2, descriptors_2 );
cout << type2str(descriptors_1.type()) << " " << descriptors_1.rows << "*" << descriptors_1.cols << endl;; //-- Step 3: Matching descriptor vectors using FLANN matcher
FlannBasedMatcher matcher;
std::vector<DMatch> matches; // the descriptor for FlannBasedMatcher should has matrix element of CV_32F
if( descriptors_1.type()!=CV_32F )
{
descriptors_1.convertTo( descriptors_1, CV_32F );
descriptors_2.convertTo( descriptors_2, CV_32F );
}
matcher.match( descriptors_1, descriptors_2, matches ); double min_dist = min_element( matches.begin(),
matches.end(),
[]( const DMatch& d1, const DMatch& d2 )->double
{
return d1.distance < d2.distance;
} )->distance; cout << min_dist << endl; vector<DMatch> good_matches; for( int i = ; i < descriptors_1.rows; i++ )
{
if( matches[i].distance < max<double>( min_dist*, 60.0 ) )
{
good_matches.push_back( matches[i]);
}
} Mat img_matches;
drawMatches( img_1, keypoints_1, img_2, keypoints_2,
good_matches, img_matches, Scalar::all(-), Scalar::all(-),
vector<char>(), DrawMatchesFlags::NOT_DRAW_SINGLE_POINTS ); //-- Show detected matches
imshow( "Good Matches", img_matches ); for( int i = ; i < good_matches.size(); i++ )
{
cout << good_matches[i].queryIdx << " --- " << good_matches[i].trainIdx << endl;
} waitKey(); return ;
} void readme()
{
cout << " Usage: ./ORB_test <img1> <img2>" << endl;
} string type2str(int type)
{
string r; uchar depth = type & CV_MAT_DEPTH_MASK;
uchar chans = + (type >> CV_CN_SHIFT); switch ( depth ) {
case CV_8U: r = "8U"; break;
case CV_8S: r = "8S"; break;
case CV_16U: r = "16U"; break;
case CV_16S: r = "16S"; break;
case CV_32S: r = "32S"; break;
case CV_32F: r = "32F"; break;
case CV_64F: r = "64F"; break;
default: r = "User"; break;
} r += "C";
r += (chans+''); return r;
}

OpenCV 3.2 FlannBasedMatcher的更多相关文章

  1. OpenCV中feature2D——BFMatcher和FlannBasedMatcher

    作者:holybin 原文:https://blog.csdn.net/holybin/article/details/40926315 Brute Force匹配和FLANN匹配是opencv二维特 ...

  2. OpenCV中的神器Image Watch

    Image Watch是在VS2012上使用的一款OpenCV工具,能够实时显示图像和矩阵Mat的内容,跟Matlab很像,方便程序调试,相当好用.跟VS2012配合使用,简直就是一款神器!让我一下就 ...

  3. OpenCV】透视变换 Perspective Transformation(续)

    载分 [OpenCV]透视变换 Perspective Transformation(续) 分类: [图像处理] [编程语言] 2014-05-27 09:39 2776人阅读 评论(13) 收藏 举 ...

  4. [OpenCV] Feature Matching

    得到了杂乱无章的特征点后,要筛选出好的特征点,也就是good matches. BruteForceMatcher FlannBasedMatcher 两者的区别:http://yangshen998 ...

  5. opencv 61篇

    (一)--安装配置.第一个程序 标签: imagebuildincludeinputpathcmd 2011-10-21 16:16 41132人阅读 评论(50) 收藏 举报  分类: OpenCV ...

  6. 3. opencv进行SIFT特征提取

    opencv中sift特征提取的步骤 使用SiftFeatureDetector的detect方法检测特征存入一个向量里,并使用drawKeypoints在图中标识出来 SiftDescriptorE ...

  7. 【OpenCV新手教程之十八】OpenCV仿射变换 &amp; SURF特征点描写叙述合辑

    本系列文章由@浅墨_毛星云 出品,转载请注明出处. 文章链接:http://blog.csdn.net/poem_qianmo/article/details/33320997 作者:毛星云(浅墨)  ...

  8. OpenCV探索之路(二十一)如何生成能在无opencv环境下运行的exe

    我们经常遇到这样的需求:我们在VS写好的程序,需要在一个没有装opencv甚至没有装vs的电脑下运行,跑出效果.比如,你在你的电脑用opencv+vs2015写出一个程序,然后老师叫你把程序发给他,他 ...

  9. OpenCV探索之路(二十三):特征检测和特征匹配方法汇总

    一幅图像中总存在着其独特的像素点,这些点我们可以认为就是这幅图像的特征,成为特征点.计算机视觉领域中的很重要的图像特征匹配就是一特征点为基础而进行的,所以,如何定义和找出一幅图像中的特征点就非常重要. ...

随机推荐

  1. ES6-模块导入导出

    基本用法 命名导出(named exports) 可以直接在任何变量或者函数前面加上一个 export 关键字,就可以将它导出. 例如: export const sqrt = Math.sqrt; ...

  2. 关于Jsp页面的jstl标签的级联属性的异常。

    使用SpringMVC框架时,当我做表单回显时. 情景描述.Employee 类有一个Department类的属性.这两个类存在多对一关联关系. 下面是Employee类的属性的定义. public ...

  3. springMvc返回Json中自定义日期格式

    (一)输出json数据 springmvc中使用jackson-mapper-asl即可进行json输出,在配置上有几点: 1.使用mvc:annotation-driven 2.在依赖管理中添加ja ...

  4. Libevent源码学习笔记一:event2/event.h

    一.libevent标准使用方法: 每个程序使用Libevent必须include <event2/event.h> 头文件,并 传给 -levent  链接器.如果只是想使用主要的eve ...

  5. 2018 Multi-University Training Contest 4 Problem B. Harvest of Apples 【莫队+排列组合+逆元预处理技巧】

    任意门:http://acm.hdu.edu.cn/showproblem.php?pid=6333 Problem B. Harvest of Apples Time Limit: 4000/200 ...

  6. 华为路由设备SSH配置

    一.环境 路由 IP:192.168.56.2 本地云 IP:192.168.56.1 二.路由器配置 [Huawei]aaa 添加用户[Huawei-aaa]local-user test pass ...

  7. Docker创建镜像文件并在容器中运行

    1.如何创建镜像文件 首先找到Docker ToolBox安装的路径,在路径下直接新建Dockerfile文件 在Dockerfile文件里写入的内容为: FROM docker/whalesay:l ...

  8. 十九、详述 IntelliJ IDEA 之 添加 jar 包

    以JDBC-MySQL驱动包为例 1.在IntelliJ IDEA中打开要添加jar包的Project 2.File – Project Structure如下图 3.选择Moudules – 再选择 ...

  9. 自定义属性之LinearLayout ImageView TextView模拟图片文字按钮

    一.资源文件: 1.文字选择器: <?xml version="1.0" encoding="utf-8"?> <selector xmlns ...

  10. 【题解】UVA10298 Power String(KMP)

    UVA10298:https://www.luogu.org/problemnew/show/UVA10298 思路 设P[x]数组为 前x个字符的最大前缀长度等于后缀字串 由P数组的定义我们可以知道 ...