标签:style blog http io color os for sp strong
一、所需软件
开发工具VS2010
opencv-2.4.9(安装路径为:D/opencv/...)
二、配置环境变量
路径:“计算机->属性->高级系统设置->环境变量->用户变量”,新建变量。如下图所示:
确定保存。
三、新建一个工程项目
1、新建一个Visual C++/Win32 控制台应用程序myOpenCV
Win32 应用程序向导最后一步中,附加选项"空项目"勾选上,完成。
2、在"解决方案资源管理器"中,右键工程名myOpenCV/属性,打开属性页窗体。左侧选择"配置属性/VC++目录",在右侧的包含目录、库目录中编辑,具体内容如下:
包含目录:
D:\opencv\build\include
D:\opencv\build\include\opencv;D:\opencv\build\include\opencv2
库目录:D:\opencv\build \x86\vc10\lib
3、还是在属性页窗体中,左侧选择"配置属性/链接器/输入",在右侧的附加依赖项中编辑,添加如下内容:(249代表版本2.4.9)
配置Debug:
opencv_calib3d249d.lib
opencv_contrib249d.lib
opencv_core249d.lib
opencv_features2d249d.lib
opencv_flann249d.lib
opencv_gpu249d.lib
opencv_highgui249d.lib
opencv_imgproc249d.lib
opencv_legacy249d.lib
opencv_ml249d.lib
opencv_objdetect249d.lib
opencv_ts249d.lib
opencv_video249d.lib
配置Release:
opencv_calib3d249.lib
opencv_contrib249.lib
opencv_core249.lib
opencv_features2d249.lib
opencv_flann249.lib
opencv_gpu249.lib
opencv_highgui249.lib
opencv_imgproc249.lib
opencv_legacy249.lib
opencv_ml249.lib
opencv_objdetect249.lib
opencv_ts249.lib
opencv_video249.lib
注:所粘贴内容即为D:\opencv\build\x86\vc10\lib下库文件名字;241表明为opencv版本号OpenCV-2.4.1,若为231即为opencv版本号OpenCV-2.3.1;Debug文件库名有d结尾,Release没有,如 opencv_ts241d.lib和 opencv_ts241.lib
配置完成后,确定,退出属性页。
4、在"解决方案资源管理器/源文件"中,右键新建一个C++文件mainForm.cpp。将一个名称为"10.jpg"的图片文件放到工程目录下面。在mainForm.cpp中添加如下代码,运行即可看到图片显示成功!
代码如下:
#include <opencv2\opencv.hpp> #include <iostream> #include <string> using namespace cv; using namespace std; int main() { Mat img = imread("10.jpg"); if(img.empty()) { cout<<"error"; return -1; } imshow("第一张照片",img); waitKey(); return 0; }
标签:style blog http io color os for sp strong
原文地址:http://www.cnblogs.com/3sxiaofu/p/4066558.html