Step 1: 安装Visual Studio
(1)下载安装Visual Studio 2015 community edition
(2)选中Visual C++ and Python tools for Visual Studio
(3)确认安装完成且无误
Step 2: 安装CMake
下载并安装CMake 3.13.0 from https://cmake.org/download/
安装过程中选择“Add CMake to system PATH”
Step 3: 下载opencv-3.4.0 and opencv_contrib-3.4.0
下载opencv-3.4.0 source code zip并解压(https://github.com/opencv/opencv/releases)
下载opencv_contrib-3.4.0 source code zip并解压(https://github.com/opencv/opencv_contrib/releases)
Step 4: 使用CMAKE生成Visual Studio project
(1)运行Cmake,在“Where is the source code”中选择OPENCV_PATH(opencv源码所在的文件夹)并在“Where to build the binaries”中选择OPENCV_PATH/build。点击”configure“,若没有提前创建"build"文件夹,系统会提醒是否创建,点击"Yes"。
选择一个编译器Visual Studio 14 2015 Win64,并使用默认参数安装。
(2)点击“INSTALL_C_EXAMPLES”
在 “OPENCV_EXTRA_MODULES_PATH”给出opencv_contrib所在的文件夹(在我们的例子中是 “D:/OpenCV/software/OpenCV3/opencv_contrib-3.4.3/modules”)
然后点击”configure“去应用这些修改项。
在Windows 10上, opencv_saliency module无法build,因此,Uncheck BUILD_opencv_saliency。然后再次点击”configure“去应用这些修改项。
(3)生成build文件。如果CMake能配置成功且没有报错,会显示“Configuring done”,点击generate.
Step 5: 编译OpenCV
(1)Release mode
打开命令窗口,进入OPENCV_PATH/build目录,并运行下面的命令:
cmake.exe --build . --config Release --target INSTALL
(2)Debug mode
打开命令窗口,进入OPENCV_PATH/build目录,并运行下面的命令:
cmake.exe --build . --config Debug --target INSTALL
Step 6: 配置环境变量
(1)在System Variables下选择Path并添加"D:\OpenCV\software\OpenCV3\opencv-3.4.3\build\install\x64\vc14\bin"
(2)在User Variables下创建OPENCV_DIR并设为"D:\OpenCV\software\OpenCV3\opencv-3.4.3\build\install"