【OpenCV学习笔记】三十六、特征检测与匹配(一)——SIFT特征点提取

时间:2021-04-17 06:25:33

特征检测与匹配(一)——SIFT特征点提取

先上ppt:

【OpenCV学习笔记】三十六、特征检测与匹配(一)——SIFT特征点提取


【OpenCV学习笔记】三十六、特征检测与匹配(一)——SIFT特征点提取


【OpenCV学习笔记】三十六、特征检测与匹配(一)——SIFT特征点提取


【OpenCV学习笔记】三十六、特征检测与匹配(一)——SIFT特征点提取


【OpenCV学习笔记】三十六、特征检测与匹配(一)——SIFT特征点提取


【OpenCV学习笔记】三十六、特征检测与匹配(一)——SIFT特征点提取


【OpenCV学习笔记】三十六、特征检测与匹配(一)——SIFT特征点提取


【OpenCV学习笔记】三十六、特征检测与匹配(一)——SIFT特征点提取


【OpenCV学习笔记】三十六、特征检测与匹配(一)——SIFT特征点提取


【OpenCV学习笔记】三十六、特征检测与匹配(一)——SIFT特征点提取


【OpenCV学习笔记】三十六、特征检测与匹配(一)——SIFT特征点提取

代码:SIFT特征点提取

//SIFT特征点提取
#include "opencv2/opencv.hpp"
using namespace cv;
#include <iostream>
using namespace std;
#include <opencv2/nonfree/nonfree.hpp>//SIFT相关
int main()
{
Mat srcImg1 = imread("00.jpg",CV_LOAD_IMAGE_COLOR);
Mat srcImg2 = imread("01.jpg", CV_LOAD_IMAGE_COLOR);
Mat dstImg1 = srcImg1.clone();
Mat dstImg2 = srcImg2.clone();
//定义SIFT特征检测类对象
SiftFeatureDetector siftDetector;//SiftFeatureDetector是SIFT类的别名
//定义KeyPoint变量
vector<KeyPoint> keyPoints1;
vector<KeyPoint> keyPoints2;
//特征点检测
siftDetector.detect(srcImg1, keyPoints1);
siftDetector.detect(srcImg2, keyPoints2);
//绘制特征点(关键点)
drawKeypoints(srcImg1, keyPoints1, dstImg1, Scalar::all(-1), DrawMatchesFlags::DRAW_RICH_KEYPOINTS);
drawKeypoints(srcImg2, keyPoints2, dstImg2, Scalar::all(-1), DrawMatchesFlags::DRAW_RICH_KEYPOINTS);
//显示结果
imshow("dstImg1", dstImg1);
imshow("dstImg2", dstImg2);
waitKey(0);
return 0;
}

运行结果:

【OpenCV学习笔记】三十六、特征检测与匹配(一)——SIFT特征点提取

【OpenCV学习笔记】三十六、特征检测与匹配(一)——SIFT特征点提取