VS2010 + OpenCV2.4.3

转载一篇关于VS2010 + OpenCV2.4.3安装及环境配置等,非常实用。在此感谢原创者。

 

一.OpenCV的编译安装:
1
.解压OpenCV-2.4.3.exe -> D:\OpenCV\Resources\OpenCV-2.4.3\opencv
2.运行CMake,为VS编译.
Where is the source code(源码): D:\OpenCV\Resources\OpenCV-2.4.3\opencv
Where is build the binaries(目标): D:\OpenCV\Resources\OpenCV-2.4.3\opencv\vs2010
Configure: 选择 Visual Studio 10\?
Generate: 生成目标

3.打开D:\OpenCV\Resources\OpenCV-2.4.3\opencv\vs2010,用对应版本的VS打开OpenCV.sln...
   A.编译OpenCV方案Debug版本:
(1),编译OpenCV方案(Debug): 在VS工作区界面左侧方案浏览器(Solution Explorer)中选中最顶项方案"Solution 'OpenCV' (61 projects)",确定Solution Configure为Debug,右键执行Build Soluton(编译方案);

(2),编译ALL_BUILD项目(Debug): 在VS工作区界面左侧方案浏览器(Solution Explorer)列表中选中项目"ALL_BUILD",确定Solution Configure为Debug,右键执行Build(编译项目);

(3),编译CMakeTargets\INSTALL项目(Debug): 在VS工作区界面左侧方案浏览器(Solution Explorer)列表中选中"CMakeTargets\INSTALL"项目,确定Solution Configure为Debug,右键执行Build(编译项目);

      B.编译OpenCV方案Release版本:
(1),编译OpenCV方案(Release): 在VS工作区界面左侧方案浏览器(Solution Explorer)中选中最顶项方案"Solution 'OpenCV' (61 projects)",确定Solution Configure为Release,右键执行Build Soluton(编译方案);

(2),编译ALL_BUILD项目(Release): 在VS工作区界面左侧方案浏览器(Solution Explorer)列表中选中项目"ALL_BUILD",确定Solution Configure为Release,右键执行Build(编译项目);

(3),编译CMakeTargets\INSTALL项目(Release): 在VS工作区界面左侧方案浏览器(Solution Explorer)列表中选中"CMakeTargets\INSTALL"项目,确定Solution Configure为Release,右键执行Build(编译项目);

4.检查编译后的结果:
D:\OpenCV\Resources\OpenCV-2.4.3\opencv\vs2010\bin: 有Debug\Release两目录及相关文件资源;
D:\OpenCV\Resources\OpenCV-2.4.3\opencv\vs2010\lib: 有Debug\Release两目录及相关文件资源;
D:\OpenCV\Resources\OpenCV-2.4.3\opencv\vs2010\install: 有bin\include\lib三目录及相关文件资源;
其它可不要求

5.应用配置:
a.将编译好的目录D:\OpenCV\Resources\OpenCV-2.4.3\opencv\vs2010\install复制到C:\,并改名为C:\opencv;
b.增加OSXP系统变量Path: c:\opencv\bin (供OpenCV的exe应用程序调用);
c.增加OSXP系统变量OPENCV: 值为: C:\opencv;

---------------------------------------------
二.程序项目配置:
特别注意: 对项目属性的配置应注意Debug\Release两个版本各配置项的统一性,否则会引起可能的编译出错,如:Common Language Runtime Support(公共语言运行库支持): Common Language Runtime Support\(clr) (公共语言运行库支持(\clr)),否则将会导致编译出错!

6.VS应用(VS2010.控制台应用程序):
(1),VS中新建win32控制台应用项目,下一步,完成。新出现的项目在源文件上右击新建一个C++源文件,在空白页上加入范例程序(如将D:\OpenCV\Resources\OpenCV-2.4.3\opencv\samples\cpp\drawing.cpp中程序复制到新建源文件空白上,如下设置好后运行即可),

在VS项目属性中设置有下:

Configuration Properties(属性)\...
a, General(常规):
Use of MFC(MFC的使用): Use Standard Windows Libraries(使用标准 Windows 库)
Use of ATL(ALT的使用): Not Using ATL(不使用 ATL)
Common Language Runtime Support(公共语言运行库支持): No Common Language Runtime Support(无公共语言运行库支持,其它选项会出错)
b, C\C++\General:
Additonal Include Directories(附加包含目录): D:\OpenCV\Resources\OpenCV-2.4.3\opencv\build\include; D:\OpenCV\Resources\OpenCV-2.4.3\opencv\build\include\opencv; D:\OpenCV\Resources\OpenCV-2.4.3\opencv\build\include\opencv2 (可勾选Inherit from parent or project defaults(继承父级或项目默认值))
c, Linker\General:
Additonal Library Directories(附加库目录): D:\OpenCV\Resources\OpenCV-2.4.3\opencv\build\x86\vc10\lib (可勾选Inherit from parent or project defaults(继承父级或项目默认值))

d, Linker(链接器)\Input(输入)\Additional Libraries(附加依赖项):为项目属性引入库:
Release版本:...............
opencv_core243.lib
opencv_highgui243.lib
opencv_video243.lib
opencv_photo243.lib
opencv_calib3d243.lib
opencv_contrib243.lib
opencv_features2d243.lib
opencv_flann243.lib
opencv_gpu243.lib
opencv_imgproc243.lib
opencv_legacy243.lib
opencv_ml243.lib
opencv_nonfree243.lib
opencv_objdetect243.lib
opencv_stitching243.lib
opencv_ts243.lib
opencv_videostab243.lib
Debug版本...................
opencv_core243d.lib
opencv_highgui243d.lib
opencv_video243d.lib
opencv_photo243d.lib
opencv_calib3d243d.lib
opencv_contrib243d.lib
opencv_features2d243d.lib
opencv_flann243d.lib
opencv_gpu243d.lib
opencv_imgproc243d.lib
opencv_legacy243d.lib
opencv_ml243d.lib
opencv_nonfree243d.lib
opencv_objdetect243d.lib
opencv_stitching243d.lib
opencv_ts243d.lib
opencv_videostab243d.lib


(2),在VS项目源码包含引用:
\\可用...
#include <opencv2\opencv.hpp>
#include <opencv2\core\core.hpp>
#include <opencv2\highgui\highgui.hpp>

#pragma comment( lib, "opencv_highgui243d.lib" )
#pragma comment( lib, "opencv_core243d.lib" )
#pragma comment( lib, "opencv_ml243d.lib" )
#pragma comment( lib, "opencv_imgproc243d.lib" )

using namespace cv;

 

你可能感兴趣的:(VS2010 + OpenCV2.4.3)