要点:
1) XP+ Visual Stuio 2010 + OpenCV-2.4.2.exe + cmake-2.8.8-win32-x86.exe
2) 如何CMake OpenCV源代码得到可编译的VS2010项目
3) 如何使用VS2010编译OpenCV源码
4) 如何配置OpenCV工程
1. 下载OpenCV 安装包
OpenCV-2.4.2.exe (
http://sourceforge.net/projects/opencvlibrary/files/opencv-win/2.4.2/)
2. 解压安装包
双击OpenCV-2.4.2.exe 解压,比如解压安装到C:\openCV_extract
【这里面是OpenCV自带的dll库,无法用来在VS中调试OpenCV,所以需要使用CMake重新编译】
3. 安装CMake
cmake-2.8.8-win32-x86.exe (
http://www.cmake.org/cmake/resources/software.html)
4. CMake OpenCV
源代码选择OpenCV安装目录C:/openCV_extract/opencv
Build目录可以设置为C:/openCV-extract/opencv_build
点击Configure
完成后,出现红色背景,
勾选
BUILD_SHARED_LIBS,BUILD_TESTS,OPENCV_BUILD_3DPARTY_LIBS,以及下面的WITH_JASPER,WITH_JPEG,WITH_PNG,
WITH_TBB(一般这个没默认选上),
和WITH_TIFF选项
点击Generate
![](https://img-my.csdn.net/uploads/201301/05/1357370740_5568.png)
5. 编译CMake出来的工程
(1)打开C:/openCV-extract/opencv_build目录下的VS2010工程文件OpenV.sln
(2)分别使用Debug和Release模式,编译生成。
(3)
复制opencv_build目录下的bin和lib文件夹,到C:\openCV_extract\opencv目录下
复制opencv\build\include 目录下的两个文件夹,到opencv\include 下,覆盖。
这样得到的库文件,就可以被VS2010调用了。
6. 配置系统环境变量
在PATH变量中添加:
C:\openCV_extract\opencv\build\x86\vc10\bin;C:\ openCV_extract \opencv\bin\Debug\;C:\ openCV_extract \opencv\bin\Release\
7. 新建Win32工程,配置工程属性
(1)VC++ Directories 下的Include Directories
(bin\debug可以不用加)
![](https://img-my.csdn.net/uploads/201301/05/1357370746_4664.png)
(2)VC++ Directories 下的Library Directories
Debug模式为:lib\Debug
Release模式为:lib\Release
![](https://img-my.csdn.net/uploads/201301/05/1357370749_8841.png)
(3)添加库文件 Linker --> Input --> Additional Dependencies (注意:lib文件名根据不同的opencv版本而定)
Debug模式添加:
opencv_calib3d242d.lib
Release模式添加:opencv_contrib242d.libopencv_core242d.libopencv_features2d242d.libopencv_flann242d.libopencv_gpu242d.libopencv_haartraining_engined.libopencv_highgui242d.libopencv_imgproc242d.libopencv_legacy242d.libopencv_ml242d.libopencv_objdetect242d.libopencv_ts242d.libopencv_video242d.lib
opencv_calib3d242.lib
8. 编码运行opencv_contrib242.libopencv_core242.libopencv_features2d242.libopencv_flann242.libopencv_gpu242.libopencv_haartraining_engine.libopencv_highgui242.libopencv_imgproc242.libopencv_legacy242.libopencv_ml242.libopencv_objdetect242.libopencv_ts242.libopencv_video242.lib