opencv2 SURF



#include "opencv2/core/core.hpp"
#include <opencv2/nonfree/features2d.hpp>
#include "opencv2/highgui/highgui.hpp"
#include <opencv2/nonfree/nonfree.hpp>
#include <opencv2/legacy/legacy.hpp>
#include <iostream>
using namespace cv;
using namespace std;

int main()
{
 //载入素材图
 Mat srcImage1 = imread("2.jpg", 1);
 Mat srcImage2 = imread("1.jpg", 1);
 if (!srcImage1.data || !srcImage2.data)
 {
  printf("读取图片错误,请确定目录下是否有imread函数指定的图片存在!\n");
  return false;
 }
 //使用surf算子检查关键点
 int minHessian = 700;//surf中的hessian阈值
 SurfFeatureDetector detector(minHessian);
 std::vector<KeyPoint> keypoint1, keypoint2;
 //调用detect函数检测出surf特征关键点,保存在vector容器中
 detector.detect(srcImage1, keypoint1);
 detector.detect(srcImage2, keypoint2);
 //计算描述符
 SurfDescriptorExtractor extractor;
 Mat descriptors1, descriptors2;
 extractor.compute(srcImage1, keypoint1, descriptors1);
 extractor.compute(srcImage2, keypoint2, descriptors2);
 //使用bruteforce进行匹配,实例化一个匹配器
 BruteForceMatcher<L2<float>> matcher;
 std::vector<DMatch> matches;
 //匹配两幅图中的描述子
 matcher.match(descriptors1, descriptors2, matches);
 //绘制从两个图像中匹配出的关键点
 Mat imgmatches;
 drawMatches(srcImage1, keypoint1, srcImage2, keypoint2, matches, imgmatches);
 imshow("  ", imgmatches);   //imshow("图片", imgmatches);之间因为有汉字,所以一直会报error:常量中有换行符,尽量不要使用汉字,一般尽量不要用汉字

 waitKey(0);
 return 0;
}

//后面更改错误后,也是一直显示不出来两幅图片,是因为两幅图片太过于相似

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值