1. 下载安装Opencv,去官网即可下载最新版本的Opencv,此处用的是Opencv 2.4.10
安装时傻瓜式的,最新版本的安装就是相当于解压到你指定的安装目录
2. 配置环境变量,我的电脑——属性——高级——环境变量
编辑PTAH:
对于32位系统,添加:
"; xx你的安装目录xx\opencv\build\x86\vc10\bin”(用“;”进行分隔)
而对于64位系统,可以两个都添加上:
”; xx你的安装目录xx\opencv\build\x86\vc10\bin”
和”; xx你的安装目录xx\opencv\build\x64\vc10\bin”
3. VS2010中的配置
A.工程包含目录配置
菜单栏里面点<视图>--<属性管理器>,在新出现的“属性管理器”工作区中,点击项目->Debug|Win32->Microsoft.Cpp.Win32.userDirectories(右键属性,或者双击)即可打开属性页面。
【通用属性】 ->【VC++目录】 ->【包含目录】中添加
E:\opencv\opencv\opencv\build\include
E:\opencv\opencv\opencv\build\include\opencv
E:\opencv\opencv\opencv\build\include\opencv2 这三个目录。
注意,根据自己不同的路径修改;
B. 工程库目录配置
属性管理器”工作区中,点击项目->Debug|Win32->Microsoft.Cpp.Win32.userDirectories(反键属性,或者双击)打开属性页面。
接着上步,就是在【通用属性】 ->【VC++目录】 ->【库目录】中,添加
E:\opencv\opencv\build\x86\vc10\lib
C. 链接库配置
“属性管理器”工作区中,点击项目->Debug|Win32->Microsoft.Cpp.Win32.userDirectories(反键属性,或者双击)即可打开属性页面。【通用属性】 ->【链接器】->【输入】->【附加的依赖项】,添加如下内容:
opencv_ml2410d.lib
opencv_calib3d2410d.libopencv_contrib2410d.libopencv_core2410d.libopencv_features2d2410d.libopencv_flann2410d.libopencv_gpu2410d.libopencv_highgui2410d.libopencv_imgproc2410d.libopencv_legacy2410d.libopencv_objdetect2410d.libopencv_ts2410d.libopencv_video2410d.libopencv_nonfree2410d.libopencv_ocl2410d.libopencv_photo2410d.libopencv_stitching2410d.libopencv_superres2410d.libopencv_videostab2410d.lib opencv_objdetect2410.libopencv_ts2410.libopencv_video2410.libopencv_nonfree2410.libopencv_ocl2410.libopencv_photo2410.libopencv_stitching2410.libopencv_superres2410.libopencv_videostab2410.libopencv_calib3d2410.libopencv_contrib2410.libopencv_core2410.libopencv_features2d2410.libopencv_flann2410.libopencv_gpu2410.libopencv_highgui2410.libopencv_imgproc2410.libopencv_legacy2410.libopencv_ml2410.lib4. 测试代码
- #include <iostream>
- #include <opencv2/core/core.hpp>
- #include <opencv2/highgui/highgui.hpp>
- using namespace cv;
- int main()
- {
- Mat img=imread("pic.jpg");//读入一张图片
- namedWindow("Test"); //创建一个名为Test窗口
- imshow("Test",img); //窗口中显示图像
- 10. waitKey(5000); //等待5000ms后窗口自动关闭
11. }