首页 > 代码库 > vs2013配置opencv2.4.9
vs2013配置opencv2.4.9
配置环境变量
- 在系统变量里面新建变量,名为 OPENCV ,值为自己解压opencv路径下的build路径,如 F:\opencv\build。
- 在系统变量里面编辑 Path 变量,在末尾添加 ;%OPENCV%\x86\vc12\bin 。环境变量设置好后最好注销(重启)一下系统.
- 新建文件opencv249.props,添加到项目中:属性管理器-右键-添加现有属性表
<?xml version="1.0" encoding="utf-8"?><Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> <ImportGroup Label="PropertySheets" /> <PropertyGroup Label="UserMacros" /> <PropertyGroup> <IncludePath>$(OPENCV)\include;$(IncludePath)</IncludePath> <LibraryPath Condition="‘$(Platform)‘==‘Win32‘">$(OPENCV)\x86\vc12\lib;$(LibraryPath)</LibraryPath> <LibraryPath Condition="‘$(Platform)‘==‘X64‘">$(OPENCV)\x64\vc12\lib;$(LibraryPath)</LibraryPath> </PropertyGroup> <ItemDefinitionGroup> <Link Condition="‘$(Configuration)‘==‘Debug‘"> <AdditionalDependencies>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_ml249d.lib;opencv_nonfree249d.lib;opencv_objdetect249d.lib;opencv_ocl249d.lib;opencv_photo249d.lib;opencv_stitching249d.lib;opencv_superres249d.lib;opencv_ts249d.lib;opencv_video249d.lib;opencv_videostab249d.lib;%(AdditionalDependencies)</AdditionalDependencies> </Link> <Link Condition="‘$(Configuration)‘==‘Release‘"> <AdditionalDependencies>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;opencv_nonfree249.lib;opencv_objdetect249.lib;opencv_ocl249.lib;opencv_photo249.lib;opencv_stitching249.lib;opencv_superres249.lib;opencv_ts249.lib;opencv_video249.lib;opencv_videostab249.lib;%(AdditionalDependencies)</AdditionalDependencies> </Link> </ItemDefinitionGroup> <ItemGroup /></Project>
- 测试案例:正常显示照片则成功
#include <opencv2\opencv.hpp>#include <iostream>#include <string>using namespace cv;using namespace std;int main(){ Mat img = imread("123.jpg"); if (img.empty()) { cout << "error"; return -1; } imshow("照片显示", img); waitKey(); return 0;}注:把照片改名为123.jpg,然后放到工程项目放源文件的文件夹里面,也可以把opencv249.props放到该目录
通过VS界面建不同版本opencvxxx.props的修改
- VS2010对应vc10,VS2012对应vc11,VS2013对应vc12
- 将两个 AdditionalDependencies 标签内的所有lib的版本号修正即可,并在opencv的lib目录下检查一下lib名称是否对应
通过VS界面建立自己的VS项目属性表
通过界面新建的属性表要为不同的配置单独建立,导入的时候也要针对配置单独导入。
- 属性管理器 ->展开 项目名 -> 右键 Debug | Win32 -> 添加新项目属性表,添加属性表,取名为“opencv249x86.Debug.props”。
- 属性管理器 ->展开 Debug | Win32 -> 双击 新建的 opencv249x86.Debug 打开属性页面 -> VC++ 目录
- 编辑 包含目录 一栏,添加opencv的include路径,例如我的是:$(OPENCV)\include
- 编辑 库目录 一栏,添加opencv的lib路径,例如我的是 :$(OPENCV)\x86\vc12\lib
- 在属性页面 -> 链接器 -> 输入 -> 附加依赖项 -> 编辑。添加下面的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_ml249d.lib opencv_nonfree249d.lib opencv_objdetect249d.lib opencv_ocl249d.lib opencv_photo249d.lib opencv_stitching249d.lib opencv_superres249d.lib opencv_ts249d.lib opencv_video249d.lib opencv_videostab249d.lib
- 确定两次后完成Debug版本的属性表编辑。
Release版:
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 opencv_nonfree249.lib opencv_objdetect249.lib opencv_ocl249.lib opencv_photo249.lib opencv_stitching249.lib opencv_superres249.lib opencv_ts249.lib opencv_video249.lib opencv_videostab249.lib
注:唯一的差别是Debug版用到的dll和lib文件都有后缀d,Release版应用的不带d。设备Release的附加依附项时别忘了把d删掉
<?xml version="1.0" encoding="utf-8"?><Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> <ImportGroup Label="PropertySheets" /> <PropertyGroup Label="UserMacros" /> <PropertyGroup> <IncludePath>$(OPENCV)\include;$(IncludePath)</IncludePath> <LibraryPath>$(OPENCV)\x86\vc12\lib;$(LibraryPath)</LibraryPath> </PropertyGroup> <ItemDefinitionGroup> <Link> <AdditionalDependencies>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_ml249d.lib;opencv_nonfree249d.lib;opencv_objdetect249d.lib;opencv_ocl249d.lib;opencv_photo249d.lib;opencv_stitching249d.lib;opencv_superres249d.lib;opencv_ts249d.lib;opencv_video249d.lib;opencv_videostab249d.lib;%(AdditionalDependencies)</AdditionalDependencies> </Link> </ItemDefinitionGroup> <ItemGroup /></Project>
<?xml version="1.0" encoding="utf-8"?><Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> <ImportGroup Label="PropertySheets" /> <PropertyGroup Label="UserMacros" /> <PropertyGroup> <IncludePath>$(OPENCV)\include;$(IncludePath)</IncludePath> <LibraryPath>$(OPENCV)\x86\vc12\lib;$(LibraryPath)</LibraryPath> </PropertyGroup> <ItemDefinitionGroup> <Link> <AdditionalDependencies>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;opencv_nonfree249.lib;opencv_objdetect249.lib;opencv_ocl249.lib;opencv_photo249.lib;opencv_stitching249.lib;opencv_superres249.lib;opencv_ts249.lib;opencv_video249.lib;opencv_videostab249.lib;%(AdditionalDependencies)</AdditionalDependencies> </Link> </ItemDefinitionGroup> <ItemGroup /></Project>
设置64位方法:(上面全改成x64)
- 在解决方案中, right-click 项目/属性/链接器/高级/目标计算机/x64
- 在解决方案中, right-click 项目/属性, 点击右上角 配置管理器,Debug和Release的平台设置成x64
- 在解决方案中, right-click 项目/清理