特征检测方法
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的库没能找到,看看之后有没有看到什么解决办法。