OpenCV2.4.3在VS2010下的安装

 

目前opencv的最新版本为OpenCV2.4.3。

下载地址为:OpenCV-2.4.3.exe

 

最近要开始学习opencv了,所以在网上查找了OpenCV2.4.3的安装方法,现在自己整理了下:

 

1.下载OpenCV-2.4.3.exe

2. 双击exe解压到自己想安装的目录,我解压到的目录为:

D:\Program Files\OPencv2.4.3

 

3. 配置环境变量,在系统环境变量配置下面的环境变量,经过测试,只需要在系统变量下配置,并不需要在用户变量下也配置。(与opencv2.4.2不同的是,此时因为2.4.3版本的opencv内嵌了TBB的功能,所以取消了TBB直接安装,这样就不需要再配置TBB环境变量了。)

              变量名:                   变量值:

               PATH:             D:\Program Files\OPencv2.4.3\opencv\build\x86\vc10\bin

 

4.打开VS2010,建立一个Win32空的控制台程序helloopencv

View->Property Manager(视图—>属性管理器),在窗口左侧原来的Solution Explorer的位置出现Property Manager页面(使属性管理器一栏显示出来),选择Debug|Win32下面的Microsoft.Cpp.Win32.user,弹出Microsoft.Cpp.Win32.userProperty属性页如下:

 

 

在弹出的窗口中,找到VC++ 目录,进行针对Debug的目录配置。

在Include Directories(包含目录)中,加入目录:

D:\Program Files\OPencv2.4.3\opencv\build\include

D:\Program Files\OPencv2.4.3\opencv\build\include\opencv

D:\Program Files\OPencv2.4.3\opencv\build\include\opencv2

在库目录下加入:

D:\Program Files\OPencv2.4.3\opencv\build\x86\vc10\lib

 

5.设置项目属性。在SolutionExplorer的helloopencv上右键选择Properties,在弹出的helloopencvProperty Pages窗口中,在链接器Link下的输入Input,为项目的Debug配置增加附加依赖项AdditionalDependecies:


opencv_calib3d243d.lib; opencv_contrib243d.lib; opencv_core243d.lib;opencv_features2d243d.lib; opencv_flann243d.lib; opencv_gpu243d.lib;opencv_highgui243d.lib; opencv_imgproc243d.lib; opencv_legacy243d.lib;opencv_ml243d.lib; opencv_objdetect243d.lib; opencv_ts243d.lib; opencv_video243d.lib

(可根据实际需要删减)

 

同理,为项目的Release选项增加依赖项,操作过程类似,只是在helloopencv最左侧的Configuration中,下拉选项选择“Release”即可。Release中需要增加的依赖项为:

opencv_calib3d243.lib; opencv_contrib243.lib; opencv_core243.lib;opencv_features2d243.lib; opencv_flann243.lib; opencv_gpu243.lib;opencv_highgui243.lib; opencv_imgproc243.lib; opencv_legacy243.lib; opencv_ml243.lib;opencv_objdetect243.lib; opencv_ts243.lib; opencv_video243.lib

(可根据实际需要删减)

 

6.为项目添加test.cpp。

代码如下:

 1 #include <opencv2/opencv.hpp>   
 2   
 3 using namespace std;  
 4 using namespace cv;  
 5   
 6 int main(int argc, char* argv[])  
 7 {  
 8     const char* imagename = "core.jpg";  
 9   
10     //从文件中读入图像   
11     Mat img = imread(imagename);  
12   
13     //如果读入图像失败   
14     if(img.empty())  
15     {  
16         fprintf(stderr, "Can not load image %s\n", imagename);  
17         return -1;  
18     }  
19   
20     //显示图像   
21     imshow("image", img);  
22   
23     //此函数等待按键,按键盘任意键就返回   
24     waitKey();  
25   
26     return 0;  
27 }  

编译运行此例程需要将core.jpg文件放在项目目录下,即与生成的.exe文件同位置。

 

 

 

 

posted @ 2012-11-23 23:27  紫清婷  阅读(5759)  评论(5编辑  收藏  举报