最近在学特征提取与图像匹配,一开始是在Python环境下使用OpenCV的,后来总是发生各种问题。于是下定决心打算转战C++的OpenCV。本篇博文是Opencv_C++版本的第一篇。将会介绍cv的具体安装方法和配置方法。实话说,一路走下来还真是不太容易。
我们要在已经安装好VS2015的基础之上,安装OpenCV以及附属的包(这个比较麻烦),并且配置VS环境,最终使得我们可以在C++环境下进行计算机视觉开发。
1.OpenCV 3.2——https://opencv.org/opencv-3-2.html
2.OpenCV_contrib 3.2——https://github.com/opencv/opencv_contrib/releases
3.CMake——https://cmake.org/download/
下载点击如图所示:
1.打开OpenCV 3.2安装包,将所有文件解压到D盘某目录下(也可以自己定义,只要自己记得,我的所有应用都编号了,所以有个53)
2.将contrib文件夹解压后放到OpenCV3.2解压的路径位置,如图所示:
3.打开opencv文件夹,新建一个文件夹mybuild:
1.打开CMake gui.exe,前两行路径按照如下方法配置:
2.点击configure,选择Visual Studio 14 2015 Win64,点击Finish,等待编译完成
3.完成后,中间对话框变红,找到OPENCV_EXTRA_MODULES_PATH 项,将contrib下的modules文件夹目录复制到value中:
4.点击Generate选项,完成之后在mybuild文件夹中找到OpenCV.sln文件,打开会显示VS界面,此时找到INSTALL选项,右击“生成”:
5.经过长时间的等待之后,编译完成,我们发现mybuild文件夹下多了一个install:
1.新建空工程,点击属性管理器下的Debug|x64,右击此项,打开属性:
2.点击VC++目录,其中“包含目录”和“库目录”分别配置如下:
3.在附加依赖项中添加:
IlmImfd.lib
ippicvmt.lib
libjasperd.lib
libjpegd.lib
libpngd.lib
libprotobufd.lib
libtiffd.lib
libwebpd.lib
opencv_aruco320d.lib
opencv_bgsegm320d.lib
opencv_bioinspired320d.lib
opencv_calib3d320d.lib
opencv_ccalib320d.lib
opencv_core320d.lib
opencv_datasets320d.lib
opencv_dnn320d.lib
opencv_dpm320d.lib
opencv_face320d.lib
opencv_features2d320d.lib
opencv_flann320d.lib
opencv_fuzzy320d.lib
opencv_hdf320d.lib
opencv_highgui320d.lib
opencv_imgcodecs320d.lib
opencv_imgproc320d.lib
opencv_line_descriptor320d.lib
opencv_ml320d.lib
opencv_objdetect320d.lib
opencv_optflow320d.lib
opencv_phase_unwrapping320d.lib
opencv_photo320d.lib
opencv_plot320d.lib
opencv_reg320d.lib
opencv_rgbd320d.lib
opencv_saliency320d.lib
opencv_shape320d.lib
opencv_stereo320d.lib
opencv_stitching320d.lib
opencv_structured_light320d.lib
opencv_superres320d.lib
opencv_surface_matching320d.lib
opencv_text320d.lib
opencv_tracking320d.lib
opencv_video320d.lib
opencv_videoio320d.lib
opencv_videostab320d.lib
opencv_xfeatures2d320d.lib
opencv_ximgproc320d.lib
opencv_xobjdetect320d.lib
opencv_xphoto320d.lib
zlibd.lib
4.新建源文件,输入以下代码,测试:
#include
#include
using namespace cv;
using namespace std;
int main(int argc,char** argv)
{
Mat src = imread("E:/Important_Project/VS_Project/ConsoleApplication3/ORB_1.jpg");
imshow("input", src);
waitKey(0);
return 0;
}
5.如果出现一大堆"error LNK2038"不匹配的问题,则右击工程,选择属性,C/C++下的运行库,修改为多线程调试/MTD,就不会报错了.
大功告成:
多美的卢浮宫!想去!