图像特征点—SIFT特征点
图像特征点—SIFT特征点
关于SIFT特征点,以下三篇博客说的非常详细,再次不再赘述。
https://mp.weixin.qq.com/s/XVB88f119gRqpwTTRvTyrA
https://mp.weixin.qq.com/s/Vx-8xsXd6aXoJupr0BEMow
https://mp.weixin.qq.com/s/8WAgDmc1R_9rGRjM9eanDg
OpenCV 代码测试
#include <iostream>
#include<opencv2/highgui/highgui.hpp>
#include<opencv2/imgproc/imgproc.hpp>
#include <opencv2/opencv.hpp>
#include<opencv2/xfeatures2d.hpp>
#include<opencv2/core/core.hpp>
using namespace cv;
using namespace std;
using namespace cv::xfeatures2d;
int main()
{
Mat image = imread("../pig.jpg");
Ptr<Feature2D> sift = xfeatures2d::SIFT::create();
vector<KeyPoint> kps;
Mat descriptor;
sift->detect(image,kps);
sift->compute(image,kps,descriptor);
Mat outImage;
drawKeypoints(image,kps,outImage,Scalar::all(-1),0);
imshow("SIFT",outImage);
cout<<"特征点的数量:"<<kps.size()<<endl;
cout<<"描述子的维度:"<<descriptor.size()<<endl;
waitKey(0);
}
测试效果
PS :Opencv中SIFT运行时直接报错问题
在用SIFT函数时,opencv报出一下错误:
OpenCV(3.4.3) Error: The function/feature is not implemented (This algorithm is patented and is excluded in this configuration; Set OPENCV_ENABLE_NONFREE CMake option and rebuild the library) in cv::xfeatures2d::SIFT::create, file D:\library\opencv-3.4.3\opencv_contrib-3.4.3\modules\xfeatures2d\src\sift.cpp, line 1207
原因是在编译opencv时没有选择 OPENCV_ENABLE_NONFREE。按照网上的说法,只要cmake时勾选这部分,然后重新编译即可。但是本机在配置了其他环境之后Opencv编译过程总是出错。
无奈之下只能调用ROS中的Opencv,调用方式如下:
set(OpenCV_DIR /opt/ros/kinetic/share/OpenCV-3.3.1-dev)
find_package(OpenCV REQUIRED)
include_directories(${OPenCV_DIRS})
参考博客:
https://blog.csdn.net/fxmfxm9304/article/details/86093564
https://blog.csdn.net/zhoukehu_CSDN/article/details/83145026