win10 vs2015配置opencv2.4.9和opencv3.2.0

为vs2015同时配置opencv2和opencv3的版本,opencv3以后的一些功能(sifi,surf算法等)移到contrib中,如需使用这些功能需要单独配置contrib,为避免麻烦,这里同时配置opencv2和opencv3两个版本,方便使用。后面我会写博客介绍opencv3的contrib的配置。

配置opencv2.4.9

官网下载opencv2.4.9

打开“opencv\\2.4.9\\opencv\\build\\x86”,我们发现目录下只有vc10,vc11,vc12,并没有vc14(对应的是vs2015)。这里是没有关系的,涉及到vc的都配置成vc12就可以了。

配置环境变量

编辑系统环境变量中的path变量,添加D:\\Program Files\\opencv2.4.9\\opencv\\build\\x86\\vc12\\bin(这个目录和你安装的opencv的位置有关,下面同理)

新建工程

添加源文件,代码如下:

1
2
3
4
5
6
7
8
9
10
11
12
#include<iostream> 
#include<opencv2/opencv.hpp>

using namespace cv;

int main()
{
Mat img = imread("1.jpg");
namedWindow("1");
imshow("1", img);
waitKey(6000);
}

然后视图中选择属性管理器->Debug win32 ->Microsoft.Cpp.Win32.user,单击右键,选择属性。

配置VC++目录的包含目录和库目录

包含目录为: D:Program Files\opencv2.4.9\opencv\build\include D:Program Files\opencv2.4.9\opencv\build\include\opencv D:Program Files\opencv2.4.9\opencv\build\include\opencv2 库目录为: D:Program Files\opencv2.4.9\opencv\build\x86\vc12\lib

添加附加依赖项

选择链接器,选择输入,然后点击附加依赖项。 添加2.4.9的lib

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
opencv_ml249d.lib
opencv_calib3d249d.lib
opencv_contrib249d.lib
opencv_core249d.lib
opencv_features2d249d.lib
opencv_flann249d.lib
opencv_gpu249d.lib
opencv_highgui249d.lib
opencv_imgproc249d.lib
opencv_legacy249d.lib
opencv_objdetect249d.lib
opencv_ts249d.lib
opencv_video249d.lib
opencv_nonfree249d.lib
opencv_ocl249d.lib
opencv_photo249d.lib
opencv_stitching249d.lib
opencv_superres249d.lib
opencv_videostab249d.lib
opencv_objdetect249.lib
opencv_ts249.lib
opencv_video249.lib
opencv_nonfree249.lib
opencv_ocl249.lib
opencv_photo249.lib
opencv_stitching249.lib
opencv_superres249.lib
opencv_videostab249.lib
opencv_calib3d249.lib
opencv_contrib249.lib
opencv_core249.lib
opencv_features2d249.lib
opencv_flann249.lib
opencv_gpu249.lib
opencv_highgui249.lib
opencv_imgproc249.lib
opencv_legacy249.lib
opencv_ml249.lib

运行项目

然后管理器设为Debug,X86运行项目。 成功运行出来图片,则表示配置成功。 如果运行出现缺少*.dll的错误,将对应的dll全部复制到操作系统目录下可解决问题。 具体如下:将D:\\Program Files\\opencv2.4.9\\opencv\\build\\x86\\vc12\\bin的所有文件复制到C:WindowsSystems32和C:WindowsSysWow64。

配置opencv3.2.0

配置环境变量

1
D:Program Files\opencv3.2.0\opencv\build\x64\vc14\bin

配置包含目录和库目录

属性管理器->Dubug x64 ->Microsoft.Cpp.x64.user,单击右键属性。 包含目录为:

1
2
3
D:Program Files\opencv3.2.0\opencv\build\include
D:Program Files\opencv3.2.0\opencv\build\include\opencv
D:Program Files\opencv3.2.0\opencv\build\include\opencv2

库目录为:

1
D:Program Files\opencv3.2.0\opencv\build\x64\vc14\lib

配置附加依赖项

1
2
opencv_world320d.lib
opencv_world320.lib

运行项目

管理器设为Dubug x64运行项目 至此win10上vs2015配置opencv2.4.9和opencv3.2.0完成。