opencv4使用SURF等函数进行图像特征点处理

由于SURF等函数存在版权问题,在opencv4的版本中无法直接使用,需要使用第三方库才行,本人在opencv4.4.0版本上进行编译了。

下载opencv4.4.0源码
下载opencv_contrib4.4.0

然后按照此步骤安装

使用案例

#include <iostream>
#include<opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <opencv2/imgproc/imgproc.hpp>
#include <opencv4/opencv2/xfeatures2d.hpp>
using namespace std;
using namespace cv;
using namespace xfeatures2d;

int main()
{
    Mat srcImage1 = imread("93.jpg",IMREAD_GRAYSCALE);
    Mat srcImage2 = imread("95.jpg",IMREAD_GRAYSCALE);

    //判断文件是否读取成功
    if (srcImage1.empty() || srcImage2.empty())
    {
        cout << "图像加载失败!";
        return -1;
    }
    else
        cout << "图像加载成功..." << endl << endl;

    //检测两幅图像中的特征点
    int minHessian = 2000;      
     Ptr<cv::xfeatures2d::SURF> detector = cv::xfeatures2d::SURF::create(minHessian);
    // SurfFeatureDetector detector(minHessian);     //老版本  
    vector<KeyPoint>keypoint1, keypoint2;          
    detector->detect(srcImage1, keypoint1);
    detector->detect(srcImage2, keypoint2);

    //计算特征向量的描述子

	Ptr <cv::xfeatures2d::SURF> descriptorExtractor = cv::xfeatures2d::SURF::create(minHessian);;
    Mat descriptors1, descriptors2;

    descriptorExtractor->compute(srcImage1, keypoint1, descriptors1);
    descriptorExtractor->compute(srcImage2, keypoint2, descriptors2);

    //使用BruteForceMatcher进行描述符匹配
    BFMatcher matcher(NORM_L2);
    vector<DMatch>matches;
    matcher.match(descriptors1, descriptors2, matches);

    //绘制匹配特征点
    Mat matchImage;
    drawMatches(srcImage1, keypoint1, srcImage2, keypoint2, matches, matchImage);

    //显示匹配的图像
    namedWindow("Match", WINDOW_AUTOSIZE);
    imshow("Match", matchImage);

    waitKey(0);
    return 0;
}

编译命令

g++  -I/usr/local/include/opencv4/ surf1.cpp -o surf1 -L/usr/local/lib/ -lopencv_features2d -lopencv_xfeatures2d -lopencv_highgui -lopencv_imgcodecs -lopencv_imgproc -lopencv_core -lopencv_photo

结果
在这里插入图片描述

  • 0
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值