为VS2010/VS2012/VS2013/OpenCV3和OpenCV2.4.11配置属性-添加OpenCV不同版本的属性表 详细图解

Table of Contents

 

属性配置有两种方法:

OpenCV3.0.0+VS2013属性表配置

添加环境变量

新建一个项目

找出属性管理器Property Manager

添加属性表Property Sheet

​​​​​​​配置Include Directories(包含目录)

​​​​​​​配置Library Directories(库目录)

Linker链接器配置->重启VS2013。

OpenCV3.0​​​​​​​懒人版本:伸手党看这里

​​​​​​​最终测试

​​​​​​​新增另外一个版本的属性表Property Sheet

​​​​​​​OpenCV2.4.11版本的配置

Path路径:

Include Directories(包含目录)

Library Directories(库目录)

Linker链接器配置

OpenCV2.4.11属性表Property Sheet Xml配置:


​​​​​​​

属性配置有两种方法:

方法一:我为每个版本的opencv建两个项目属性文件(debuge 和release下各一个),vs的每个工程只需要添加相应版本的属性文件即可。【推荐此种做法,博客下文也是以此为主介绍】

本博文先以OpenCV 3.0.0版+VS2013的配置为准,其他版本和他一样,区别就是环境变量Path路径、库目录、Linker链接器填入的内容不一样,后面有给OpenCV2.4.11版本的详细信息

 

方法二:可以通过Microsoft.Cpp.Win32.user这个属性表来配置,

优点:一次配置,终身使用

缺点:所有的Visual Studio的项目都会用到OpenCV,其他不需要使用OpenCV的项目也会用到。解决办法是将下图的复选框取消。每次都要这样勾选,会很麻烦~

OpenCV3.0.0+VS2013属性表配置

添加环境变量

OpenCV2.4.11

 

OpenCV3.0.0

D:\OpenCV\opencv300\build\x86\vc12\bin

D:\OpenCV\opencv300\build\x64\vc12\bin

 

 

OpenCV3.2及以上没有x86版,大家可以用Cmake自行编译,可参考这篇文章

《opencv3.2在vs2015开发环境搭建+cmake3.8编译生成opencv x86版本库》

https://blog.csdn.net/sinat_27953939/article/details/68948313

 

另外一篇文章是如何新建x64编译器的,大家也可以参考下

《OpenCV3.4.3最新版本安装详解!VS2013平台下,解决X86没有问题。《OpenCV3编程入门》第1章基本知识--学习笔记2》

https://blog.csdn.net/qq_15698613/article/details/83592039

​​​​​​​新建一个项目

新建一个项目test,如下图(这时没有属性管理器)

 

​​​​​​​

找出属性管理器Property Manager

VS2013的路径:

View-Other Windows-Property Managemer

“视图”—“属性管理器”—右击项目“添加现有属性”【VS2015/VS2017等大同小异,大家自己找一下】

​​​​​​​添加属性表Property Sheet

“Debug | Win32”右击->Add New Project Property Sheet...

Name填OpenCV300Debug.props

Location选择D:\OpenCV\opencv300

【这个目录是我OpenCV3.0.0存放的地方,各位以自己存放的路径为准。OpenCV解压缩下来就会创建一个opencv文件夹,将属性表放在这个文件夹下即可】

属性管理器Property Manager多了一个OpenCV300Debug,然后双击开始配置

​​​​​​​配置Include Directories(包含目录)

在OpenCV300 Property Pages属性页添加Include Directories(包含目录),内容如下:

点击OK

D:\OpenCV\opencv300\build\include

D:\OpenCV\opencv300\build\include\opencv

D:\OpenCV\opencv300\build\include\opencv2

​​​​​​​配置Library Directories(库目录)

在OpenCV300 Property Pages属性页添加Library Directories(库目录)“D:\OpenCV\opencv300\build\x86\vc12\lib”,截图内容如下:

点击OK

最好不要手动输入路径,而是去预览里面指定,否则有可能会出错,无法打开文件“opencv_calib3d2411.lib”。

lib与Visual Studio对应关系如下:

vc8 = Visual Studio 2005,

vc9 = Visual Studio 2008,

vc10 = Visual Studio 2010,

vc11 = Visual Studio 2012,

vc12 = Visual Studio 2013。

Linker链接器配置->重启VS2013。

​​​​​​​​​​​​​​OpenCV3.0【OpenCV2.4版本的后面再讲】

Debug版:

opencv_ts300d.lib

opencv_world300d.lib

release版:

opencv_ts300.lib

opencv_world300.lib

OpenCV3.0​​​​​​​懒人版本:伸手党看这里

在D:\OpenCV\opencv300【这个目录是我OpenCV3.0.0存放的地方】下新建一个txt文件,里面填入以下内容,然后改名为OpenCV300Debug.props即可。

OpenCV300Debug.props配置的xml档

<?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>D:\OpenCV\opencv300\build\include;D:\OpenCV\opencv300\build\include\opencv;D:\OpenCV\opencv300\build\include\opencv2;$(IncludePath)</IncludePath>
    <LibraryPath>D:\OpenCV\opencv300\build\x86\vc12\lib;$(LibraryPath)</LibraryPath>
  </PropertyGroup>
  <ItemDefinitionGroup>
    <Link>
      <AdditionalDependencies>opencv_ts300d.lib;opencv_world300d.lib</AdditionalDependencies>
    </Link>
  </ItemDefinitionGroup>
  <ItemGroup />
</Project>

​​​​​​​最终测试

新建一个main.cpp文件,输入以下代码【OpenCV2和OpenCV3都可以使用】

注意:在main.cpp同目录下放一张图片,取名为"1.jpg"

#include <opencv2/opencv.hpp>
using namespace cv;

int main()
{
	Mat img = imread("1.jpg");
	imshow("Load Picture", img);
	waitKey(6000);
	return 0;
}

在属性管理器Property Manager添加属性表,分别为Debug|Win32和Release|Win32添加属性表OpenCV300Debug.props和OpenCV300Release.props,Build时选择对应的版本Debug或Release。

我电脑下生成的exe程序:

Debug版是62KB,Release版只有12KB。

程序效果:

​​​​​​​新增另外一个版本的属性表Property Sheet

新增另外一个版本的属性表Property Sheet时需要将原来正在使用中的属性表Remove掉,否则会出现下面的画面

OpenCV300Debug->右击->Remove

双击OpenCV300Release开始配置,步骤同上

​​​​​​​OpenCV2.4.11版本的配置

Path路径:

D:\OpenCV\opencv2411\build\x86\vc12\bin

D:\OpenCV\opencv2411\build\x64\vc12\bin

Include Directories(包含目录)

D:\OpenCV\opencv2411\build\include;

D:\OpenCV\opencv2411\build\include\opencv;

D:\OpenCV\opencv2411\build\include\opencv2

Library Directories(库目录)

D:\OpenCV\opencv2411\build\x86\vc12\lib

Linker链接器配置

【我这边没有将debug版与Release版分开,需要的自己更改】

19个带d的Debug版在前

19个不带d的Release版在后

opencv_ml2411d.lib

opencv_calib3d2411d.lib

opencv_contrib2411d.lib

opencv_core2411d.lib

opencv_features2d2411d.lib

opencv_flann2411d.lib

opencv_gpu2411d.lib

opencv_highgui2411d.lib

opencv_imgproc2411d.lib

opencv_legacy2411d.lib

opencv_objdetect2411d.lib

opencv_ts2411d.lib

opencv_video2411d.lib

opencv_nonfree2411d.lib

opencv_ocl2411d.lib

opencv_photo2411d.lib

opencv_stitching2411d.lib

opencv_superres2411d.lib

opencv_videostab2411d.lib

opencv_objdetect2411.lib

opencv_ts2411.lib

opencv_video2411.lib

opencv_nonfree2411.lib

opencv_ocl2411.lib

opencv_photo2411.lib

opencv_stitching2411.lib

opencv_superres2411.lib

opencv_videostab2411.lib

opencv_calib3d2411.lib

opencv_contrib2411.lib

opencv_core2411.lib

opencv_features2d2411.lib

opencv_flann2411.lib

opencv_gpu2411.lib

opencv_highgui2411.lib

opencv_imgproc2411.lib

opencv_legacy2411.lib

opencv_ml2411.lib

OpenCV2.4.11属性表Property Sheet Xml配置:

<?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>D:\OpenCV\opencv2411\build\include;D:\OpenCV\opencv2411\build\include\opencv;D:\OpenCV\opencv2411\build\include\opencv2;$(IncludePath)</IncludePath>
    <LibraryPath>D:\OpenCV\opencv2411\build\x86\vc12\lib;$(LibraryPath)</LibraryPath>
    <_PropertySheetDisplayName>OpenCV2411Debug</_PropertySheetDisplayName>
  </PropertyGroup>
  <ItemDefinitionGroup>
    <Link>
      <AdditionalDependencies>opencv_ml2411d.lib;opencv_calib3d2411d.lib;opencv_contrib2411d.lib;opencv_core2411d.lib;opencv_features2d2411d.lib;opencv_flann2411d.lib;opencv_gpu2411d.lib;opencv_highgui2411d.lib;opencv_imgproc2411d.lib;opencv_legacy2411d.lib;opencv_objdetect2411d.lib;opencv_ts2411d.lib;opencv_video2411d.lib;opencv_nonfree2411d.lib;opencv_ocl2411d.lib;opencv_photo2411d.lib;opencv_stitching2411d.lib;opencv_superres2411d.lib;opencv_videostab2411d.lib;opencv_objdetect2411.lib;opencv_ts2411.lib;opencv_video2411.lib;opencv_nonfree2411.lib;opencv_ocl2411.lib;opencv_photo2411.lib;opencv_stitching2411.lib;opencv_superres2411.lib;opencv_videostab2411.lib;opencv_calib3d2411.lib;opencv_contrib2411.lib;opencv_core2411.lib;opencv_features2d2411.lib;opencv_flann2411.lib;opencv_gpu2411.lib;opencv_highgui2411.lib;opencv_imgproc2411.lib;opencv_legacy2411.lib;opencv_ml2411.lib;%(AdditionalDependencies)</AdditionalDependencies>
    </Link>
  </ItemDefinitionGroup>
  <ItemGroup />
</Project>

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值