OpenCV2.4.9在Visual Studio 2013下的配置

Reference:

1)http://opencv-srf.blogspot.com/2013/05/installing-configuring-opencv-with-vs.html

2)A book named “OpenCV2 Computer Vision Application Programming Cookbook”, Page 11-18;

3)http://blog.csdn.net/poem_qianmo/article/details/19809337

4)http://blog.csdn.net/mdl13412/article/details/8289972

5)http://docs.opencv.org/doc/tutorials/introduction/windows_visual_studio_Opencv/windows_visual_studio_Opencv.html#windows-visual-studio-how-to

 

1.下载visual studio 2013软件和OpenCV2.4.9

1visual studio 2013下载免费版:

https://www.dreamspark.com/Product/Product.aspx?productid=72

在这个网址下,先注册一个账户,再用学校的邮箱验证,就可以免费下载、使用了vs2013了。如下图所示:



2)下载OpenCV2.4.9goto the website

地址如下:http://opencv.org/downloads.html

 

2. 配置环境变量(environment variables)

1) 新建一个用户或者系统变量(二者任选一个即可)

我选的是to build a user variable。变量名:OPENCV2_DIR,变量值:D:\OpenCV249\opencv\build。这是因为我将OpenCV2.4.9解压库到D:\OpenCV249这个目录下了,所以变量值相应的设成这个了。


2)添加系统路径

Now you are going to edit a systemvariable.

i) click 'Path'or 'PATH' inside the list of System variables and then click 'Edit' buttonat the bottom of the window.

ii) Then add asemicolon(即:分号“;”) to the endof the line and add the following %OPENCV2_DIR%\x86\vc12\bin  after the semicolon. X86 isyour system architecture and vc12 is the compiler type. How to find your systemarchitecture and compiler type is explained at the beginning of the post.(Don't delete anything. Just append it at the end of the line.)

 

注:后面的图片中显示的路径是“x64”,那是因为我理解我的操作系统是64bits的,就用了x64,结果发现程序调试时会有错误,如下:

 

可以理解这段话:

其实配置选择什么跟64位还是32位操作系统没有直接的关系,而是在于编译你的程序时候,是使用那个编译器。


编译器选的是win32,就用x86编译器选的是X64,就用X64。不过一般情况下,都是用的win32的X86编译器。所以,无论32还是64位操作系统,配置文件最好都选择x86版的。另外,这里的vc10表示vs2010,如果是其他版本的visual studio,稍微调整一下即可。

 

3. Configure Visual Studio2013

1)创建一个简单的visual studio 2013win32Console Application

File|New Project| Project …

2) Create a Property Sheet

Tobe able to compile and run your future OpenCV application, you need to tellVisual C++ where to find the OpenCV libraries and include files. Since you willprobably create several OpenCV projects in the future, the best option is tocreate a Property Sheet that you will be able to reuse from project to project.This is done through thePropertyManager. 如果Property Manager未显示在IDE中,可以通过View 菜单调出该项。


 

3)先做Debug | win 32

A)Edit the Include Directories textfieldand add the path to the include files of your OpenCV library.


BDo the samething with theLibrary Directories. See the followingpicture.

 

C) the next step is to specify the OpenCVlibrary files which need to be linked with your code in order to produce anexecutable application. 索性就把所有的modules都添加进来。Note: 这些文件是以字母d结尾的,d 代表debug;

 

4)再做Release | win 32

参考步骤3)先做Debug | win 32Note: 这些文件不是以字母d结尾的,对应代表release模式。

n   Summary

UserVariable:

OPENCV2_DIR= D:\OpenCV249\opencv\build;

$(OPENCV2_DIR)\include

%OPENCV2_DIR%\x86\vc12\bin

$(OPENCV2_DIR)\x86\vc12\lib


4. 一个小例子测试一下:

#include<iostream> 

#include<opencv2/core/core.hpp> 

#include<opencv2/highgui/highgui.hpp> 

usingnamespace cv;

usingnamespace std;

 

int main()

{

    // 读入一张图片

    Mat img = imread("D:\\tiger.jpg");

    if (!img.data)

    {

        cout << "No image hasnot been created"<<endl;

    }

    // 创建一个名为 "Fig1"窗口 

    cvNamedWindow("Fig1");

    // 在窗口中显示改图 

    imshow("Fig1", img); 

    waitKey();

    return 0;

}

 

Result:


5. 附录OPENCV2.4.9 – x86 lib文件名:

1) 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

 

2) debug

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

6. 一些编译、运行时的错误(详见Reference 3)
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值