目录
- 下载
- (可选 —— 二选一)添加环境变量
- 新建项目和配置
- 配置包含目录
- 配置库目录
- 添加库
- (可选 —— 二选一)添加dll文件的路径
- 测试
平台:Windows 10 20H2
Visual Studio 2015
OpenCV 2.4.13.6
本文参考自最新opencv-c++安装及配置教程(VS2019 C++ & opencv4.4.0) —— /我爱西红柿炒鸡蛋/
及vs2013 配置 OpenCV2.4.9和 OpenCV3.3 多版本共存 —— Galaxy.Dong
之前已安装过OpenCV 4.5.3,由于需要用到OpenCV 2.4.13.6,故作此记录
下载
官方下载:Releases - OpenCV
选择需要的版本,本文中选择OpenCV – 2.4.13.6
下载完成后打开
输入要存放的位置并开始解压
(可选 —— 二选一)添加环境变量
此电脑-属性-高级系统设置
高级-环境变量
编辑Path
添加bin文件夹的路径
新建项目和配置
新建项目后配置项目的属性
配置包含目录
(根据所需选择平台)
添加解压后opencv文件夹内的include文件夹及其子文件夹的路径,如
D:\Work\OpenCV\opencv2\opencv\build\include
D:\Work\OpenCV\opencv2\opencv\build\include\opencv
D:\Work\OpenCV\opencv2\opencv\build\include\opencv2
配置库目录
(根据所需选择平台)
添加所需架构的路径
如
D:\Work\OpenCV\opencv2\opencv\build\x64\vc14\lib
添加库
(根据所需选择平台)
加入lib文件夹下的以".lib"结尾的库文件名
其中以"d.dll"结尾的为Debug时需要的库
不带’d’的则为Release时需要的库
这些文件名可用如下python脚本提取
import os
filePath = r'D:\Work\OpenCV\opencv2\opencv\build\x64\vc14\lib'DebugLibList = []
ReleaseLibList = []for _ in os.listdir(filePath):if _.endswith('d.lib'):DebugLibList.append(_)elif _.endswith('.lib'):ReleaseLibList.append(_)print("DebugLibList:\n")
for _ in DebugLibList:print(_)print("\nReleaseLibList:\n")
for _ in ReleaseLibList:print(_)
Debug Libs
opencv_calib3d2413d.lib
opencv_contrib2413d.lib
opencv_core2413d.lib
opencv_features2d2413d.lib
opencv_flann2413d.lib
opencv_gpu2413d.lib
opencv_highgui2413d.lib
opencv_imgproc2413d.lib
opencv_legacy2413d.lib
opencv_ml2413d.lib
opencv_nonfree2413d.lib
opencv_objdetect2413d.lib
opencv_ocl2413d.lib
opencv_photo2413d.lib
opencv_stitching2413d.lib
opencv_superres2413d.lib
opencv_ts2413d.lib
opencv_video2413d.lib
opencv_videostab2413d.lib
Release Libs
opencv_calib3d2413.lib
opencv_contrib2413.lib
opencv_core2413.lib
opencv_features2d2413.lib
opencv_flann2413.lib
opencv_gpu2413.lib
opencv_highgui2413.lib
opencv_imgproc2413.lib
opencv_legacy2413.lib
opencv_ml2413.lib
opencv_nonfree2413.lib
opencv_objdetect2413.lib
opencv_ocl2413.lib
opencv_photo2413.lib
opencv_stitching2413.lib
opencv_superres2413.lib
opencv_ts2413.lib
opencv_video2413.lib
opencv_videostab2413.lib
(可选 —— 二选一)添加dll文件的路径
(根据所需选择平台)
添加
PATH=D:\Work\OpenCV\opencv2\opencv\build\x64\vc14\bin;%PATH%
路径为dll文件所在的路径
测试
#include <iostream>
using namespace std;#include <opencv2/opencv.hpp>
using namespace cv;int main(int argc, char * argv[])
{Mat TestImg = Mat(500, 500, CV_8UC3, Scalar(0, 255, 0));namedWindow("TestImg");imshow("TestImg", TestImg);waitKey(0);return 0;
}