VS2013安装oepncv2.4.10 以及opencv 3.0.0

Author:Maddock 

Date:2014.12.27

……………………………………………………………………………………………………

PS: VS2013 + OPENCV 3.0.0 的安装,连接器的输入选项简化为:

#ifndef _OPENCV_LIB_
#define _OPENCV_LIB_

#ifdef _DEBUG
#pragma comment(lib, "opencv_ts300d.lib")
#pragma comment(lib, "opencv_world300d.lib")

#else
#pragma comment(lib, "opencv_ts300.lib")
#pragma comment(lib, "opencv_world300.lib")

#endif

#endif

 

其他步骤相同。

不过,目前opencv3.0.0的using namespace cv和windows.h中ACCESS_MASK定义冲突,

错误    4    error C2872: “ACCESS_MASK”: 不明确的符号    c:\program files (x86)\windows kits\8.1\include\um\winnt.h    9084    1    opencvtest

注释掉using namespace cv,再所有需要用到cv的地方加cv::……………………………………………………………………………………………

准备工具 windows平台 opencv2.4.10 vs2013

1解压opencv2.4.10.exe,我放在目录 C:\Adisk\software\opencv\opencv2410\opencv

配置环境变量

Path: C:\Adisk\software\opencv\opencv2410\opencv\build\x86\vc12\bin

在x86文件夹内还有vc10,vc11,vc12 3个文件夹,分别对应vs2010,vs2012,vs2013

2 配置VS2013的include 和lib目录

新建win32工程,打开属性管理器(视图–>其他窗口–>属性管理器)

右键Debu32中的Mirosoft.Cpp.Win32.user选择属性,可以看见

编辑包含目录和库目录

包含目录 C:\Adisk\software\opencv\opencv2410\opencv\build\include

库目录 C:\Adisk\software\opencv\opencv2410\opencv\build\x86\vc12\lib

下一步点击连接器的输入选项,编辑附加依赖项,加入

opencv的debug版本和release版本需要的lib不同,但是在编辑右键Debu32中的Mirosoft.Cpp.Win32.user选择属性这一步中,相应的

release版本也跟着变了,如果编译运行debug版本是没有问题,切换到release版本是需要把debug版本去掉,否则opencv中的部分函数将不能

运行。

debug版本
opencv_calib3d2410d.lib
opencv_contrib2410d.lib
opencv_core2410d.lib
opencv_features2d2410d.lib
opencv_flann2410d.lib
opencv_gpu2410d.lib
opencv_highgui2410d.lib
opencv_imgproc2410d.lib
opencv_legacy2410d.lib
opencv_ml2410d.lib
opencv_nonfree2410d.lib
opencv_objdetect2410d.lib
opencv_ocl2410d.lib
opencv_photo2410d.lib
opencv_stitching2410d.lib
opencv_superres2410d.lib
opencv_ts2410d.lib
opencv_video2410d.lib
opencv_videostab2410d.lib

release版本
opencv_calib3d2410.lib
opencv_contrib2410.lib
opencv_core2410.lib
opencv_features2d2410.lib
opencv_flann2410.lib
opencv_gpu2410.lib
opencv_highgui2410.lib
opencv_imgproc2410.lib
opencv_legacy2410.lib
opencv_ml2410.lib
opencv_nonfree2410.lib
opencv_objdetect2410.lib
opencv_ocl2410.lib
opencv_photo2410.lib
opencv_stitching2410.lib
opencv_superres2410.lib
opencv_ts2410.lib
opencv_video2410.lib
opencv_videostab2410.lib

 

3  测试

// opencvtest.cpp : 定义控制台应用程序的入口点。
//

#include "stdafx.h"
#include
using namespace cv;
using namespace std;

int _tmain(int argc, _TCHAR* argv[])
{
    Mat src = imread("image.png", 0);
    if (src.empty())
    {
        cout << "打开图像失败!" << endl;
        return -1;
    }
    namedWindow("image", CV_WINDOW_AUTOSIZE);
    imshow("image", src);
    waitKey(0);
    return 0;
}

如果出现dll文件丢失,可以注销账户或者重启电脑是环境变量生效。

 

PS: 按照上述方法做的时候,在debug和release界面的附加依赖项里其中一个编辑完,另一个为什么也出现了和其一样的附加依赖项?怎么实现debug和release中的附加依赖项不一样?? 哪位大侠知道解决方法,求告知!!!!!

参考方案:
每次编写代码在前面加入下面的代码,可以不用配置编辑附加依赖项
参考来源:http://blog.csdn.net/xiaohuh421/article/details/7476485

#ifdef _DEBUG
#pragma comment(lib,"..\\debug\\LedCtrlBoard.lib")
#else
#pragma comment(lib,"..\\release\\LedCtrlBoard.lib")
#endif

#ifdef _DEBUG
#pragma comment(lib, "opencv_calib3d2410d.lib")
#pragma comment(lib, "opencv_contrib2410d.lib")
#pragma comment(lib, "opencv_core2410d.lib")
#pragma comment(lib, "opencv_features2d2410d.lib")
#pragma comment(lib, "opencv_flann2410d.lib")
#pragma comment(lib, "opencv_gpu2410d.lib")
#pragma comment(lib, "opencv_highgui2410d.lib")
#pragma comment(lib, "opencv_imgproc2410d.lib")
#pragma comment(lib, "opencv_legacy2410d.lib")
#pragma comment(lib, "opencv_ml2410d.lib")
#pragma comment(lib, "opencv_nonfree2410d.lib")
#pragma comment(lib, "opencv_objdetect2410d.lib")
#pragma comment(lib, "opencv_photo2410d.lib")
#pragma comment(lib, "opencv_stitching2410d.lib")
#pragma comment(lib, "opencv_ts2410d.lib")
#pragma comment(lib, "opencv_video2410d.lib")
#pragma comment(lib, "opencv_videostab2410d.lib")
#else
#pragma comment(lib, "opencv_calib3d2410.lib")
#pragma comment(lib, "opencv_contrib2410.lib")
#pragma comment(lib, "opencv_core2410.lib")
#pragma comment(lib, "opencv_features2d2410.lib")
#pragma comment(lib, "opencv_flann2410.lib")
#pragma comment(lib, "opencv_gpu2410.lib")
#pragma comment(lib, "opencv_highgui2410.lib")
#pragma comment(lib, "opencv_imgproc2410.lib")
#pragma comment(lib, "opencv_legacy2410.lib")
#pragma comment(lib, "opencv_ml2410.lib")
#pragma comment(lib, "opencv_nonfree2410.lib")
#pragma comment(lib, "opencv_objdetect2410.lib")
#pragma comment(lib, "opencv_photo2410.lib")
#pragma comment(lib, "opencv_stitching2410.lib")
#pragma comment(lib, "opencv_ts2410.lib")
#pragma comment(lib, "opencv_video2410.lib")
#pragma comment(lib, "opencv_videostab2410.lib")
#endif

 

如果觉得每次添加比较麻烦,可以采用如下一劳永逸的方案:

新建一个opencv_lib.h文件,编辑内容:

#ifndef _OPENCV_LIB_
#define _OPENCV_LIB_

#ifdef _DEBUG
#pragma comment(lib, "opencv_calib3d2410d.lib")
#pragma comment(lib, "opencv_contrib2410d.lib")
#pragma comment(lib, "opencv_core2410d.lib")
#pragma comment(lib, "opencv_features2d2410d.lib")
#pragma comment(lib, "opencv_flann2410d.lib")
#pragma comment(lib, "opencv_gpu2410d.lib")
#pragma comment(lib, "opencv_highgui2410d.lib")
#pragma comment(lib, "opencv_imgproc2410d.lib")
#pragma comment(lib, "opencv_legacy2410d.lib")
#pragma comment(lib, "opencv_ml2410d.lib")
#pragma comment(lib, "opencv_nonfree2410d.lib")
#pragma comment(lib, "opencv_objdetect2410d.lib")
#pragma comment(lib, "opencv_photo2410d.lib")
#pragma comment(lib, "opencv_stitching2410d.lib")
#pragma comment(lib, "opencv_ts2410d.lib")
#pragma comment(lib, "opencv_video2410d.lib")
#pragma comment(lib, "opencv_videostab2410d.lib")
#else
#pragma comment(lib, "opencv_calib3d2410.lib")
#pragma comment(lib, "opencv_contrib2410.lib")
#pragma comment(lib, "opencv_core2410.lib")
#pragma comment(lib, "opencv_features2d2410.lib")
#pragma comment(lib, "opencv_flann2410.lib")
#pragma comment(lib, "opencv_gpu2410.lib")
#pragma comment(lib, "opencv_highgui2410.lib")
#pragma comment(lib, "opencv_imgproc2410.lib")
#pragma comment(lib, "opencv_legacy2410.lib")
#pragma comment(lib, "opencv_ml2410.lib")
#pragma comment(lib, "opencv_nonfree2410.lib")
#pragma comment(lib, "opencv_objdetect2410.lib")
#pragma comment(lib, "opencv_photo2410.lib")
#pragma comment(lib, "opencv_stitching2410.lib")
#pragma comment(lib, "opencv_ts2410.lib")
#pragma comment(lib, "opencv_video2410.lib")
#pragma comment(lib, "opencv_videostab2410.lib")
#endif

#endif

将该文件放入opencv的安装目录:C:\Adisk\software\opencv\opencv2410\opencv\build\include\opencv2\opencv_lib.h也就是和 #include 在同一个目录,之后只需要包含头文件 #include

就可以在Debug和Release版本之间任意切换

 

你可能感兴趣的:(VS2013安装oepncv2.4.10 以及opencv 3.0.0)