要点:
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
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可以不用加)
(2)VC++ Directories 下的Library Directories
Debug模式为:lib\Debug
Release模式为:lib\Release
(3)添加库文件 Linker –> Input –> Additional Dependencies (注意:lib文件名根据不同的opencv版本而定)
Debug模式添加:
opencv_calib3d242d.lib
opencv_contrib242d.lib
opencv_core242d.lib
opencv_features2d242d.lib
opencv_flann242d.lib
opencv_gpu242d.lib
opencv_haartraining_engined.lib
opencv_highgui242d.lib
opencv_imgproc242d.lib
opencv_legacy242d.lib
opencv_ml242d.lib
opencv_objdetect242d.lib
opencv_ts242d.lib
opencv_video242d.lib
Release模式添加:
opencv_calib3d242.lib
opencv_contrib242.lib
opencv_core242.lib
opencv_features2d242.lib
opencv_flann242.lib
opencv_gpu242.lib
opencv_haartraining_engine.lib
opencv_highgui242.lib
opencv_imgproc242.lib
opencv_legacy242.lib
opencv_ml242.lib
opencv_objdetect242.lib
opencv_ts242.lib
opencv_video242.lib
8. 编码运行
#include "stdafx.h" #include "highgui.h" //using namespace cv; int _tmain(int argc, _TCHAR* argv[]) { const char* imagename = "D:/Images/jc.jpg"; cv::Mat img = cv::imread(imagename); if(img.empty()) { fprintf(stderr, "Can not load image %s\n", imagename); return -1; } if( !img.data ) return -1; cv::namedWindow("image", CV_WINDOW_AUTOSIZE); cv::imshow("image", img); cv::waitKey(); return 0; } //(代码来自http://blog.sina.com.cn/s/blog_68ed8b21010163uc.html)
运行效果如下
OpenCV官方教程中文版(For Python) PDF http://www.linuxidc.com/Linux/2015-08/121400.htm
Ubuntu Linux下安装OpenCV2.4.1所需包 http://www.linuxidc.com/Linux/2012-08/68184.htm
Ubuntu 16.04上用CMake图形界面交叉编译树莓派的OpenCV3.0 http://www.linuxidc.com/Linux/2016-10/135914.htm
Ubuntu 12.04下安装OpenCV 2.4.5总结 http://www.linuxidc.com/Linux/2013-06/86704.htm
Ubuntu 10.04中安装OpenCv2.1九步曲 http://www.linuxidc.com/Linux/2010-09/28678.htm
基于QT和OpenCV的人脸识别系统 http://www.linuxidc.com/Linux/2011-11/47806.htm
[翻译]Ubuntu 14.04, 13.10 下安装 OpenCV 2.4.9 http://www.linuxidc.com/Linux/2014-12/110045.htm
OpenCV的详细介绍:请点这里
OpenCV的下载地址:请点这里
本文永久更新链接地址:http://www.linuxidc.com/Linux/2016-11/136908.htm