SURF特征点描述

本文通过使用SURF算法实现两幅图像之间的特征点检测及匹配,并利用OpenCV库完成匹配关键点的绘制与展示。
#include<iostream>
#include<opencv2/opencv.hpp>
#include<opencv2/core/core.hpp>
#include "opencv2/features2d/features2d.hpp" 
#include <opencv2/nonfree/nonfree.hpp>  
#include<opencv2/legacy/legacy.hpp> 
using namespace cv;
using namespace std;
int main()
{
    Mat orig1, orig2;
    orig1 = imread("1.jpg");
    orig2 = imread("2.jpg");
    int minHessian = 700;//SURF算法中的hessian阈值 
    SurfFeatureDetector detector(minHessian);//定义一个SurfFeatureDetector(SURF) 特征检测类对象    
    vector<KeyPoint> keyPoint1, keyPoint2;//vector模板类,存放任意类型的动态数组
    //检测特征点并存放
    detector.detect(orig1, keyPoint1);
    detector.detect(orig2, keyPoint2);
    //计算描述符(特征向量)  
    SurfDescriptorExtractor extractor;
    Mat descriptors1, descriptors2;
    extractor.compute(orig1, keyPoint1, descriptors1);
    extractor.compute(orig2, keyPoint2, descriptors2);
    BruteForceMatcher< L2<float> > matcher;
    vector< DMatch > matches;
    //匹配两幅图中的描述子(descriptors)  
    matcher.match(descriptors1, descriptors2, matches);
    //绘制从两个图像中匹配出的关键点  
    Mat imgMatches;
    drawMatches(orig1, keyPoint1, orig2, keyPoint2, matches, imgMatches);//进行绘制  
    //显示效果图  
    namedWindow("匹配图", WINDOW_NORMAL);
    imshow("匹配图", imgMatches);
    waitKey();
    return 0;
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值