OpenCV2.3.1和VS2010配置过程:
1.到http://www.opencv.org.cn/index.php/Download下载OpenCV for Windows(也即 OpenCV-2.3.1-win-superpack.exe 文件)。
2.将OpenCV-2.3.1-win-superpack.exe 解压并放到某个目录下,例如 D:\Program Files\OpenCV-2.3.1-win-superpack\opencv(无需运行setup.exe,解压则可)。
3.添加OpenCV的include和lib,步骤如下:在VS新建一个Win32控制台应用程序,以下工程Opencv为例,然后选择菜单栏视图->属性管理器
这时在VS编辑器右侧出现属性管理器
点开之前建的工程Opencv,会看到Debug|Win32和Release|Win32两个目录
点开Debug|Win32目录,
找到Microsoft.Cpp.Win32.user,双击打开
找到箭头所指的”VC++目录”,打开,在右侧在”包含目录”中加入OpenCV安装目录下的
D:\OpenCV\opencv\build\include;
D:\OpenCV \opencv\build\include\opencv;
D:\ OpenCV \opencv\build\include\opencv2;
在”引用目录”和”库目录”中加入安装目录下的D:\ OpenCV \opencv\build\x86\vc10\lib;
4.设置环境变量(系统变量和用户变量都设置)
在系统变量和用户变量的Path中加入(注意不要直接复制,可能会多出个空格,调整好格式再加到环境变量中)
D:\OpenCV \opencv\build\x86\vc10\bin;
D:\OpenCV \opencv\build\common\tbb\ia32\vc10;
加入之后需要重启。
5.重启之后打开工程,右击工程项目,选择属性
在弹出的对话框里选择”链接器->输入”
Debug模式下,在右侧附加依赖项中加入
opencv_calib3d231d.lib
opencv_contrib231d.lib
opencv_core231d.lib
opencv_features2d231d.lib
opencv_flann231d.lib
opencv_gpu231d.lib
opencv_highgui231d.lib
opencv_imgproc231d.lib
opencv_legacy231d.lib
opencv_ml231d.lib
opencv_objdetect231d.lib
opencv_ts231d.lib
opencv_video231d.lib
opencv_nonfree231d.lib
opencv_ocl231d.lib
opencv_photo231d.lib
opencv_stitching231d.lib
opencv_superres231d.lib
opencv_videostab231d.lib
Release模式下,在右侧附加依赖项中加入
opencv_calib3d231.lib
opencv_contrib231.lib
opencv_core231.lib
opencv_features2d231.lib
opencv_flann231.lib
opencv_gpu231.lib
opencv_highgui231.lib
opencv_imgproc231.lib
opencv_legacy231.lib
opencv_ml231.lib
opencv_objdetect231.lib
opencv_ts231.lib
opencv_video231.lib
opencv_nonfree231.lib
opencv_ocl231.lib
opencv_photo231.lib
opencv_stitching231.lib
opencv_superres231.lib
opencv_videostab231.lib
工程设置完成,给个验证程序,如果例程运行过程出现cannot find or open PDB file这个错误,请参照http://hi.baidu.com/%D6%F3%D2%BB%B1%AD%B2%E8/blog/item/0302b3188ef42f5143a9adf9.html的解决方法。
6.例程:
#include <opencv2/opencv.hpp>
using namespace std;
using namespace cv;
intmain(int argc, char*argv[])
{
const char* imagename = "lena.jpg";
int a;
//读取图像
Mat img = imread(imagename);
//判断是否读到图像
if(img.empty())
{
fprintf(stderr, "Cannot load image %s\n", imagename);
return -1;
}
//显示图像
imshow("image",img);
//等待任何按键按下返回
waitKey();
return 0;
}
本例程需要将下面的图片保存为lena.jpg,然后与.cpp文件放在同一个文件夹下来完成。能够显示图片则表示配置成功。