【opencv】教程代码 —features2D(2)

使用SURF算法检测两幅图关键点后暴力匹配

SURF特征检测

使用SURF(Speeded Up Robust Features)算法来检测两张图像之间的关键点,并使用FLANN(Fast Library for Approximate Nearest Neighbors)基于特征描述符向量进行匹配

图像特征点检测(SURF)、(FLANN)匹配和目标定位

1.feature_description—SURF_matching_Demo.cpp(Debug模式)使用SURF算法检测两幅图关键点后暴力匹配

5d2215a509e099110a897b45e4bcd0a7.png

box.png

9f32be968bf98412e06bc71f3decfee6.png

box_in_scene.png

708d7dfeccbd55a5a67018744f85c2be.png

minHessian=400

1aa3e6c00029a382a651dfb8fde6ed23.png

minHessian=1000

6128a411d9dad7c93dc1218bdddb225f.png

minHessian=10000

911da9be70835cf10d8a2c2ca2e25c1a.png

#include <iostream> // 包含标准输入输出流库
#include "opencv2/core.hpp" // 包括OpenCV的核心功能头文件
#ifdef HAVE_OPENCV_XFEATURES2D // 如果定义了HAVE_OPENCV_XFEATURES2D
#include "opencv2/highgui.hpp" // 包括用户界面相关功能的头文件
#include "opencv2/features2d.hpp" // 包括特征检测相关功能的头文件
#include "opencv2/xfeatures2d.hpp" // 包括特殊特征检测的头文件(非free模块)


using namespace cv; // 使用cv命名空间
using namespace cv::xfeatures2d; // 使用cv的xfeatures2d命名空间
using std::cout; // 使用标准库中的cout
using std::endl; // 使用标准库中的endl


const char* keys = // 定义命令行参数
    "{ help h |                  | Print help message. }"
    "{ input1 | box.png          | Path to input image 1. }"
    "{ input2 | box_in_scene.png | Path to input image 2. }";


int main( int argc, char* argv[] ) // 主函数
{
    CommandLineParser parser( argc, argv, keys ); // 创建命令行解析器
    Mat img1 = imread( samples::findFile( parser.get<String>("input1") ), IMREAD_GRAYSCALE ); // 读取第一张图片为灰度图
    Mat img2 = imread( samples::findFile( parser.get<String>("input2") ), IMREAD_GRAYSCALE ); // 读取第二张图片为灰度图
    if ( img1.empty() || img2.empty() ) // 如果图片读取失败
    {
        cout << "Could not open or find the image!\n" << endl; // 打印错误信息
        parser.printMessage(); // 打印帮助信息
        return -1; // 返回错误代码
    }


    //-- Step 1: Detect the keypoints using SURF Detector, compute the descriptors
    int minHessian = 400; // 设置SURF算法的Hessian阈值
    Ptr<SURF> detector = SURF::create( minHessian ); // 创建SURF特征检测器
    std::vector<KeyPoint> keypoints1, keypoints2; // 存放两张图片的关键点
    Mat descriptors1, descriptors2; // 存放两张图片的描述符
    detector->detectAndCompute( img1, noArray(), keypoints1, descriptors1 ); // 检测并计算img1的关键点和描述符
    detector->detectAndCompute( img2, noArray(), keypo
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值