OpenCV 3.2 FlannBasedMatcher
#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的更多相关文章
- OpenCV中feature2D——BFMatcher和FlannBasedMatcher
作者:holybin 原文:https://blog.csdn.net/holybin/article/details/40926315 Brute Force匹配和FLANN匹配是opencv二维特 ...
- OpenCV中的神器Image Watch
Image Watch是在VS2012上使用的一款OpenCV工具,能够实时显示图像和矩阵Mat的内容,跟Matlab很像,方便程序调试,相当好用.跟VS2012配合使用,简直就是一款神器!让我一下就 ...
- OpenCV】透视变换 Perspective Transformation(续)
载分 [OpenCV]透视变换 Perspective Transformation(续) 分类: [图像处理] [编程语言] 2014-05-27 09:39 2776人阅读 评论(13) 收藏 举 ...
- [OpenCV] Feature Matching
得到了杂乱无章的特征点后,要筛选出好的特征点,也就是good matches. BruteForceMatcher FlannBasedMatcher 两者的区别:http://yangshen998 ...
- opencv 61篇
(一)--安装配置.第一个程序 标签: imagebuildincludeinputpathcmd 2011-10-21 16:16 41132人阅读 评论(50) 收藏 举报 分类: OpenCV ...
- 3. opencv进行SIFT特征提取
opencv中sift特征提取的步骤 使用SiftFeatureDetector的detect方法检测特征存入一个向量里,并使用drawKeypoints在图中标识出来 SiftDescriptorE ...
- 【OpenCV新手教程之十八】OpenCV仿射变换 & SURF特征点描写叙述合辑
本系列文章由@浅墨_毛星云 出品,转载请注明出处. 文章链接:http://blog.csdn.net/poem_qianmo/article/details/33320997 作者:毛星云(浅墨) ...
- OpenCV探索之路(二十一)如何生成能在无opencv环境下运行的exe
我们经常遇到这样的需求:我们在VS写好的程序,需要在一个没有装opencv甚至没有装vs的电脑下运行,跑出效果.比如,你在你的电脑用opencv+vs2015写出一个程序,然后老师叫你把程序发给他,他 ...
- OpenCV探索之路(二十三):特征检测和特征匹配方法汇总
一幅图像中总存在着其独特的像素点,这些点我们可以认为就是这幅图像的特征,成为特征点.计算机视觉领域中的很重要的图像特征匹配就是一特征点为基础而进行的,所以,如何定义和找出一幅图像中的特征点就非常重要. ...
随机推荐
- SOJ4480 Easy Problem IV (并查集)
Time Limit: 3000 MS Memory Limit: 131072 K Description 据说 你和任何一个陌生人之间所间隔的人不会超过六个,也就是说,最多通过六个人你就能够认识任 ...
- PHP-------抽象和接口
静态的关键字是:static Class ren { Public static $yanse; //yanse是一个静态的成员 Static function show() ; // stat ...
- Exhaustive Search
Write a program which reads a sequence A of n elements and an integer M, and outputs "yes" ...
- fastjson是什么东东?
fastjson是一个Java语言编写的高性能功能完善的JSON库.它采用一种“假定有序快速匹配”的算法,把JSON Parse的性能提升到极致,是目前Java语言中最快的JSON库.Fastjson ...
- win7 xampp php7 yii2 配置sqlserver
第一步: https://www.microsoft.com/en-us/download/details.aspx?id=20098 下载 如下图 php7 版本 放到 xampp\php ...
- SSH框架——(二)四层结构:DAO,Service,Controller,View层
1. DAO层: 主要任务:做数据持久层的工作,负责与数据库进行联络的一些任务都封装在此. DAO层的设计:首先是设计DAO层的接口,然后再Spring的配置文件中定义此接口的实现类,然后就可以在模块 ...
- 使用腾讯云mysql的一下小坑
1. 数据库中标的命名,mybatis会给你全部转成驼峰命名,这样就会发现找不到数据库的表了.比如下面的,我在本地运行时ok, 表名称是t_blogtype,但是放到服务器就报错说找不到表. 2. 本 ...
- Redis(RedisTemplate)使用string字符串
RedisTemplate配置:https://www.cnblogs.com/weibanggang/p/10188682.html ApplicationContext applicationCo ...
- 【题解】UVA10298 Power String(KMP)
UVA10298:https://www.luogu.org/problemnew/show/UVA10298 思路 设P[x]数组为 前x个字符的最大前缀长度等于后缀字串 由P数组的定义我们可以知道 ...
- HDU 2050(折线分割平面)
传送门: http://acm.hdu.edu.cn/showproblem.php?pid=2050 折线分割平面 Time Limit: 2000/1000 MS (Java/Others) ...