在opencv3.0中,如果需要SIFT,SURF等算法的时候,需要配置opencv_contrib .
罗列一下自己在配置的过程中遇到的问题:
1.
CMake Error at D:/opencv_contrib-3.2.0/modules/dnn/cmake/download_protobuf.cmake:23 (ocv_download):
Unknown CMake command "ocv_download".
Call Stack (most recent call first):
D:/opencv_contrib-3.2.0/modules/dnn/cmake/download_protobuf.cmake:51 (ocv_protobuf_download)
D:/opencv_contrib-3.2.0/modules/dnn/cmake/OpenCVFindLibProtobuf.cmake:30 (include)
D:/opencv_contrib-3.2.0/modules/dnn/CMakeLists.txt:35 (include)
解决方案:可能使用的是opencv_contrib-3.2.0版本,网上有好多的教程,下载protobuf-cpp-3.1.0.tar.gz等,但是可能由于本人的技术有限,使用这种方法等不到解决。
所以使用的第二种方法,下载opencv_contrib-3.0.0版本,顺利通过配置。
2. error LNK2026 模块对于 SAFESEH 映像是不安全的
解决方案:属性->链接器->高级->Image Has Safe Exception Handler:NO:/SAFESEH
问题得到解决
测试代码
#include <iostream>
#include <opencv2/opencv.hpp>
#include <opencv2/xfeatures2d.hpp>
using namespace cv;
using namespace std;
int main()
{
//Create SIFT class pointer
Ptr<Feature2D> f2d = xfeatures2d::SIFT::create();
//读入图片
Mat img_1 = imread("1.tif");
Mat img_2 = imread("2.tif");
//Detect the keypoints
vector<KeyPoint> keypoints_1, keypoints_2;
f2d->detect(img_1, keypoints_1);
f2d->detect(img_2, keypoints_2);
//Calculate descriptors (feature vectors)
Mat descriptors_1, descriptors_2;
f2d->compute(img_1, keypoints_1, descriptors_1);
f2d->compute(img_2, keypoints_2, descriptors_2);
//Matching descriptor vector using BFMatcher
BFMatcher matcher;
vector<DMatch> matches;
matcher.match(descriptors_1, descriptors_2, matches);
Mat img_matches;
drawMatches(img_1, keypoints_1, img_2, keypoints_2, matches, img_matches);
imshow("match", img_matches);
waitKey(0);
}