surf特征检测与匹配

特征检测方法

SIFT
SURF:

surf特征点检测
1.使用FeatureDetector接口来发现感兴趣点。
2.使用SurfFeatureDetector以及其函数detect来实现检测过程。
3.使用drawkeypoint绘制检测到的关键点。

#include<opencv2/opencv.hpp>
#include<iostream>
#include<opencv2/xfeatures2d.hpp>
#include<vector>

using namespace std;
using namespace cv;
using namespace cv::xfeatures2d;
Mat src, gray_src;
const char* output_title = "SURF";
Mat my_resize(const Mat&, int, int);

Mat my_resize(const Mat& img, int width, int height)
{
	// 1, 定义缩放后的图像大小,行列缩放比例
	Mat output = Mat::zeros(Size(width, height), CV_8UC1);
	float width_scale = (float)img.cols / width;     // 列缩放比例,相对于算法前面讲的k1
	float height_scale = (float)img.rows / height;   // 行缩放比例,即k2

	// 2, 采样
	for (int i = 0; i < height; i++)  // 注意i,j的范围, i < height * img.rows / height;
	{
		for (int j = 0; j < width; j++)
		{
			output.at<uchar>(i, j) = img.at<uchar>(round(i * height_scale), round(j * width_scale));
		}
	}

	return output;

}

int main(int argc, char** argv) 
{
	Mat img = imread("C:\\Users\\chf\\Desktop\\课题组\\system_calibration\\2021.03.09\\1.jpg");
	if (img.empty()) {
		printf("could not load image...\n");
		return -1;
	}
	
	Mat src = my_resize(img, 300, 400); // (width, height),(col, row)
	imshow("缩放后效果", src);

	//SURF特征检测
	int minHession = 400;
	Ptr<SURF> detector = SURF::create(minHession);
	vector<KeyPoint> keypoints;
	detector->detect(src, keypoints, Mat());

	//绘制关键点
	Mat keypoint_img;
	drawKeypoints(src, keypoints, keypoint_img, Scalar::all(-1), DrawMatchesFlags::DEFAULT);

	imshow(output_title, keypoint_img);
	waitKey(0);
	return 0;
}

在都得到检测匹配点之后,使用BruteForce进行匹配,但是这里找不到相应的库,因为自己配置的C++opencv环境是之前简化配的,所以legary的库没能找到,看看之后有没有看到什么解决办法。

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值