本文以VS2017+OpenCV3.4.6+Opencv Contrib 3.4.6为例
添加SURF,SIFT算子
前期文件准备
下载Opencv:https://opencv.org/
下载高级扩展包:https://github.com/opencv/opencv_contrib/
下载Cmake工具:https://cmake.org/download/
选择与所安装Opencv版本一致的contrib
Opencv Contrib安装
打开CMAKE-GUI工具
source code选择你下载好的数据源,build the binaries设置生成路径。
点击Configure选择VS 2017 X64(根据自己的VS版本以及编译器的位数)。
以本机为例:
先点击一次configure
Finished后再添加配置,将Contrib拓展包解压,设置好路径
设置相关属性
添加SIFT,SURF使用权限和模块
勾选“BUILD_opencv_world”编译静态链接
添加Python支持(可选)
再次点击configure和generate
Open project ->生成-> 批生成->勾选Debug, Release版本生成
在install目录下生成了opencv_world 文件,即编译成功
VS环境设置
包含目录添加
D:\opencv_3.4.6\new_bulid\install\include\opencv2;
D:\opencv_3.4.6\new_bulid\install\include\opencv;
D:\opencv_3.4.6\new_bulid\install\include;
库目录添加
D:\opencv_3.4.6\new_bulid\install\x64\vc15\lib
依赖项
opencv_world346d.lib;(debug)
opencv_world346.lib;(release)
测试代码
#include"iostream"
#include"opencv.hpp"
#include"highgui.hpp"
#include"xfeatures2d.hpp"
using namespace cv;
using namespace std;
int main()
{
Mat imageL0 = imread("Pattenimage_L.bmp");
Mat imageR0 = imread("Pattenimage_R.bmp");
Mat imageL1, imageR1;
GaussianBlur(imageL0, imageL1, Size(3, 3), 0.5);
GaussianBlur(imageR0, imageR1, Size(3, 3), 0.5);
//找出特征点
Ptr<Feature2D>f2d = xfeatures2d::SURF::create();
vector<KeyPoint> keyPoint1, keyPoint2;
f2d->detect(imageL1, keyPoint1);
f2d->detect(imageR1, keyPoint2);
drawKeypoints(imageL1, keyPoint1, imageL1, Scalar::all(-1), DrawMatchesFlags::DRAW_RICH_KEYPOINTS);
drawKeypoints(imageR1, keyPoint2, imageR1, Scalar::all(-1), DrawMatchesFlags::DRAW_RICH_KEYPOINTS);
namedWindow("KeyPoints of imageL", 0);
namedWindow("KeyPoints of imageR", 0);
imshow("KeyPoints of imageL", imageL1);
imshow("KeyPoints of imageR", imageR1);
//特征点匹配
Mat descriptors_1, descriptors_2;
f2d->compute(imageL1, keyPoint1, descriptors_1);
f2d->compute(imageR1, keyPoint2, descriptors_2);
BFMatcher matcher;
vector<DMatch>matches;
matcher.match(descriptors_1, descriptors_2, matches);
Mat imageOutput;
drawMatches(imageL1, keyPoint1, imageR1, keyPoint2, matches, imageOutput);
namedWindow("picture of matching", 0);
imshow("picture of matching", imageOutput);
waitKey(0);
return 0;
}
网友评论