OpenCV学习笔记(一) 环境配置
Visual Studio 2010
VS2010对应的OpenCV的lib文件(build\x86\vc10\lib)分为debug模式和release模式两种:debug模式牺牲速度,但能提供更多信息,例如内存是否泄漏,函数调用是否正确等;release模式不执行这些检查来提高速度。
首先在系统path变量中添加dll文件的路径:
C:\ProgramFiles\opencv249\build\x86\vc12\bin
在Visual Studio中新建一个项目,打开“视图->属性管理器”,在“Debug|Win32”中右键->“添加新项目属性表”(可命名为OpenCVProjectD.props),修改:
- “VC++目录”下的可执行文件目录、包含目录、库目录
- “链接器->输入->附加依赖项”,添加结尾为d的所有lib
可执行文件目录:
C:\ProgramFiles\opencv249\build\x86\vc12\bin包含目录:
C:\ProgramFiles\opencv249\build\include C:\ProgramFiles\opencv249\build\include\opencv C:\ProgramFiles\opencv249\build\include\opencv2库目录:
C:\ProgramFiles\opencv249\build\x86\vc12\lib附加依赖项:
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
Release|Win32中新建属性表OpenCVProjectR.props,操作类似,仅在附加依赖项中添加不带d的lib文件。
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
按照这种方法配置会产生两个XML文件,之后再创建OpenCV项目时,只需将这两个文件导入该项目的属性管理器即可。
注意,OpenCV中文论坛上直接修改Microsoft.Cpp.Win32.user属性的方法不可取。这个文件在Debug和Release模式下是共用的,即Debug模式和Release模式共用所有lib,会导致一些错误,例如在Release模式下的imread函数无法运行。
Qt 5
Qt项目中的.pro文件添加以下代码:
INCLUDEPATH += D:\opencv\opencv\build\include\ INCLUDEPATH += D:\opencv\opencv\build\include\opencv\ INCLUDEPATH += D:\opencv\opencv\build\include\opencv2\ CONFIG(debug,debug|release) { LIBS += -LD:\opencv\opencv\build\x86\vc10\lib \ -lopencv_core244d \ -lopencv_highgui244d \ -lopencv_imgproc244d \ -lopencv_features2d244d \ -lopencv_calib3d244d } else { LIBS += -LD:\opencv\opencv\build\x86\vc10\lib \ -lopencv_core244 \ -lopencv_highgui244 \ -lopencv_imgproc244 \ -lopencv_features2d244 \ -lopencv_calib3d244 }
P.S.
在实际运行中遇到错误:
- 转换到COFF期间失败:网上查找的解决方案是在微软上下载SP对MSVS2010进行升级
- cl.exe:工具->选项->构建和运行,取消“使用jom代替nmake”
posted on 2014-03-01 19:54 eric.xing 阅读(1501) 评论(0) 编辑 收藏 举报