VS2010 + OpenCV 2.4.1 环境配置
(Windows 7 x64 中文旗舰版;Visual Studio 2010 中文旗舰版;OpenCV2.4.1。)
1.用户环境变量(或系统环境变量),新建或添加
PATH D:\Program Files\opencv\build\x86\vc10\bin;D:\Program Files\opencv\build\common\tbb\ia32\vc10
OPENCV D:\Program Files\opencv\build
2.建立demo,在C++下,新建一个“win32控制台程序”,“空项目”即可,输入以下代码:
#include "highgui.h"
int main()
{const char* imagename = "D:/Demo.jpg"; //随便放一张jpg图片在D盘或另行设置目录cv::Mat img = cv::imread(imagename);if(img.empty())return -1; //是否加载成功if(!img.data)return -1;cv::namedWindow("image", CV_WINDOW_AUTOSIZE);cv::imshow("image", img);cv::waitKey();return 0;
}
3.“视图”“属性管理器”中双击Demo的项目名称,“Demo属性页”->“配置属性”->“VC++目录”->“包含目录”中追加:
D:\Program Files\opencv\build\include
D:\Program Files\opencv\build\include\opencv
D:\Program Files\opencv\build\include\opencv2
4.“库目录”中追加:
D:\Program Files\opencv\build\x86\vc10\lib
5.(“配置”==“Debug”) ->“链接器”->“输入”->“附加依赖库”中追加:
opencv_core241d.lib
opencv_highgui241d.lib
opencv_video241d.lib
opencv_ml241d.lib
opencv_legacy241d.lib
opencv_imgproc241d.lib
6.(“配置”==“Release”) ->“附加依赖库”中追加:
opencv_core241.lib
opencv_highgui241.lib
opencv_video241.lib
opencv_ml241.lib
opencv_legacy241.lib
opencv_imgproc241.lib
注:
1、32位与64位都可以直接配置32位环境,如果要配置为64位,前面涉及到 “x86” 的文件夹均改为“x64” ,最后在启动调试按钮右侧点击“Win32”下拉列表,“配置管理器…”新建x64平台即可。
2、提示tbb_debug.dll丢失,只需复制以下文件到执行文件目录,或者将文件夹加入Path即可。
Win32: D:\Program Files\opencv\build\common\tbb\ia32\vc10\tbb_debug.dll
x64: D:\Program Files\opencv\build\common\tbb\intel64\vc10\tbb_debug.dll