学习笔记:OpenCV 3.2.0下Sift特征提取

在OpenCV3中,Sift、SURF等特征提取算子都被编入了opencv_contrib中,如果需要调用,需自行安装编译OpenCV3+contrib,这里我选择OpenCV 3.2.0版本。具体安装踩过的坑可以见我另一篇博客。

遇到的问题:

OpenCV2中构建Sift特征点的detector使用cv::xfeatures2d::SiftFeatureDetector直接构造,而后调用detect函数将检测出的特征点存储于格式为std::vector<cv::KeyPoint>的向量,而在OpenCV3中,函数仍可调用,且可以编译成功,但是在运行程序时会报如下的错。

OpenCV Error: The function/feature is not implemented () in detectAndCompute, file /home/yao/opencv-3.2.0/modules/features2d/src/feature2d.cpp, line 154
terminate called after throwing an instance of 'cv::Exception'
  what():  /home/yao/opencv-3.2.0/modules/features2d/src/feature2d.cpp:154: error: (-213)  in function detectAndCompute

Aborted (core dumped)

因此我们不能再使用老办法,网上的代码多是调用OpenCV2,在stackoverflow中看到过类似的问题,整理一下。

解决方案:

//定义Sift检测子
cv::Ptr<cv::xfeatures2d::SiftFeatureDetector> sift_detector = cv::xfeatures2d::SiftFeatureDetector::create();
//定义特征点向量
std::vector<cv::KeyPoint> key_points;
//检测Sift特征点
sift_detector->detect(image1, key_points);
//在灰度图上绘制特征点
cv::drawKeypoints(image1, key_points, image1);

猜你喜欢

转载自blog.csdn.net/yrc19950911/article/details/82982185