基于opencv3.1的特征检测、特征点匹配、图像拼接(二)
首先给出opencv的官方指导手册网站:
- opencv document index
- https://docs.opencv.org/3.0-last-rst/doc/tutorials/features2d/feature_detection/feature_detection.html?highlight=feature
在这个网站可以查询不同版本下的opencv的各种功能的介绍,以及不同版本下,函数如何进行的修改优化。在进行图像匹配之前,我们首先要进行特征点提取;很多相关资料并没有提及使用的opencv版本,代码比较混杂,甚至有的文章代码抄袭,给读者造成很大混乱。譬如Feature Detection部分,在opencv3.0之前的版本和opencv3.0之后的版本差异比较大;本文主要讲的是3.0之后的版本,与时俱进嘛。
再给出opencv示例图片及视频的位置,D:\opencv\sources\samples\data方便查找使用。
1. 特征检测算法
先给出opencv手册里的Feature Detection特征点获取源码
#include <stdio.h>
#include <iostream>
#include "opencv2/core.hpp"
#include "opencv2/features2d.hpp"
#include "opencv2/xfeatures2d.hpp"
#include "opencv2/highgui.hpp"
using namespace cv;
using namespace cv::xfeatures2d;
void readme();
/* @function main */
int main( int argc, char** argv )
{
if( argc != 3 )
{
readme(); return -1; }
Mat img_1 = imread( argv[1], IMREAD_GRAYSCALE );
Mat img_2 = imread( argv[2], IMREAD_GRAYSCALE );
if( !img_1.data || !img_2.data )
{
std::cout<< " --(!) Error reading images " << std::endl; return -1; }
//-- Step 1: Detect the keypoints using SURF Detector
int minHessian = 400;
Ptr<SURF> detector = SURF::create( minHessian );
std::vector<KeyPoint> keypoints_1, keypoints_2;
detector->detect( img_1, keypoints_1 );
detector->detect( img_2, keypoints_2 );
//-- Draw keypoints
Mat img_keypoints_1; Mat img_keypoints_2;
drawKeypoints( img_1, keypoints_1, img_keypoints_1, Scalar::all(-1), DrawMatchesFlags::DEFAULT );
drawKeypoints( img_2, keypoints_2, img_keypoints_2, Scalar::all

本文介绍了基于opencv3.1的特征检测、特征点匹配和图像拼接过程,重点关注了3.0版本后的变化。讨论了BruteForceMatcher和FlannBasedMatcher的匹配效果,并提出通过比较最近邻与次近邻距离的匹配方法来提升匹配稳定性。通过调整算法参数,减少了错误匹配,提高了图像拼接的准确性。
最低0.47元/天 解锁文章
2834

被折叠的 条评论
为什么被折叠?



