0%

Win10下VS2015配置编译OpenCV3.2.0_contrib x64

在Opencv3.0后续版本中,一些高级特征提取、立体视觉以及机器学习的相关库都集成在opencv_contrib包里面,使用之前需要额外编译配置。
需要的工具:
点击这里下载OpenCV3.2.0Win版本安装包
点击这里下载opencv_contrib-3.2.0.zip注意不带rc
CMake、 Visual Studio 2015

准备

将下载的opencv_contrib-3.2.0.zip解压后放到OpenCV安装目录,我这里是C:\library\opencv,在此目录下建立文件夹mybuild存放编译文件。

开始编译

打开CMake,参照下图填写路径后点击Configure进行配置
CMake
弹出窗口选择VS2015 X64点击Finish
VS2015 x64
进行如下配置:(这里供参考)

  1. OPENCV_EXTRA_MODULES_PATH填写C:\library\opencv\opencv_contrib-3.2.0\opencv_contrib-3.2.0\modules

  2. 去掉WITH_CUDA

  3. CMAKE_INSTALL_PREFIX填写C:/library/opencv/build

点击Generate生成后打开mybuild文件夹下OpenCV.sln文件,编译生成ALL_BUILDINSTALL项目即可。

配置过程中出现无法下载ippicv_windows_20151201.zip,手动下载后放到sources\3rdparty\ippicv\downloads\windows-04e81ce5d0e329c3fbc606ae32cad44d目录下重新进行Configure即可

VS2015开发环境配置

环境变量配置

Path环境变量添加C:\library\opencv\build\x64\vc14\bin

添加包含目录、库目录

新建VS2015工程,视图->其他窗口打开属性管理器,如下图所示进行配置:

在属性管理器中配置x64属性,VC++目录包含目录添加如下信息:

1
2
3
C:\library\opencv\build\include
C:\library\opencv\build\include\opencv
C:\library\opencv\build\include\opencv2

库目录中添加C:\library\opencv\build\x64\vc14\lib

链接器-输入-附加依赖项中添加:(Debug,如需Release版本请去掉d)

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
39
40
opencv_aruco320d.lib
opencv_bgsegm320d.lib
opencv_bioinspired320d.lib
opencv_calib3d320d.lib
opencv_ccalib320d.lib
opencv_core320d.lib
opencv_datasets320d.lib
opencv_dpm320d.lib
opencv_face320d.lib
opencv_features2d320d.lib
opencv_flann320d.lib
opencv_fuzzy320d.lib
opencv_imgcodecs320d.lib
opencv_imgproc320d.lib
opencv_highgui320d.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

测试

可以使用下列代码进行测试:

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
39
40
41
42
43
44
45
#include opencv2/opencv.hpp

#define PI 3.1415926
#define R 150
using namespace cv;
using namespace std;

int main()
{
Point center = Point(250, 250);
int temp = 0;
while (waitKey(60) != 27)
{
temp++;
temp = temp % 72;
float 角度 = temp / 18.0 * PI;
Mat picture(500, 500, CV_8UC3, Scalar(255, 255, 255));
// center = Point(palm[0] + 320, palm[2] + 240);
// r = palm[1] / 2;
center.x = 250 + R*sin(角度);
center.y = 250 - R*cos(角度);
int r = 20;
circle(picture, center, r, Scalar(255, 0, 0), -1);

for (int i = 1; i < 7; i++)
{
角度 = (temp - 3 * i) / 18.0 * PI;
r = 20 - i * 2;
center.x = 250 + R*sin(角度);
center.y = 250 - R*cos(角度);
circle(picture, center, r, Scalar(255, 0, 0\), -1);
}
string 内容 = "Loading...";
switch ((temp % 36) / 12)
{
case 0:内容 = "Opencv3"; break;
case 1:内容 = "Opencv3."; break;
case 2:内容 = "Opencv3.2.0"; break;
}
cv::putText(picture, 内容, cv::Point(180, 250), 3, 1, cvScalar(0, 0, 255));

imshow("Loading...", picture);
}

}

运行截图如下:
截图