首页 > 代码库 > Opencv + vs2012环境配置

Opencv + vs2012环境配置

首先获得最新的Opencv 2.4.9源码:opencv源码下载

一、Opencv环境变量配置

1.将源码安装到制定目录:

2.为Opencv 添加环境变量:计算机-->属性 点击高级系统设置

3.出来系统属性对话框后,点击环境变量。

4.弹出如下对话框:单击新建

D:\opencv\opencv\build\x86\vc11\bin;D:\opencv\opencv\build\x86\vc11\lib

二、然后再看VS2012 的配置。

1、新建工程:选择Win32控制台应用程序,为你的工程取个名字,click确定

2、添加cpp文件

#include <opencv2/opencv.hpp>    using namespace cv;  int main() {    Mat img = imread("c:/test.jpg",1);  // Mat img = imread("image.jpg");Mat grey;cvtColor(img, grey, CV_BGR2GRAY);Mat sobelx;Sobel(grey, sobelx, CV_32F, 1, 0);double minVal, maxVal;minMaxLoc(sobelx, &minVal, &maxVal); //find minimum and maximum intensitiesMat draw;sobelx.convertTo(draw, CV_8U, 255.0/(maxVal - minVal), -minVal * 255.0/(maxVal - minVal));namedWindow("src(http://blog.csdn.net/xuanyuyt)", CV_WINDOW_AUTOSIZE);imshow("src(http://blog.csdn.net/xuanyuyt)", img);imshow("dst(http://blog.csdn.net/xuanyuyt)", draw);waitKey();     return 0; } 

 

3.右键工程属性:选择VC++目录

包含目录:D:\opencv\opencv\build\include库目录:D:\opencv\opencv\build\x86\vc11\lib

4、连接器 -> 输入 -> 附加依赖项

配置选择 debug

opencv_gpu249d.libopencv_ocl249d.libopencv_photo249d.libopencv_stitching249d.libopencv_superres249d.libopencv_core249d.libopencv_imgproc249d.libopencv_highgui249d.libopencv_ml249d.libopencv_video249d.libopencv_features2d249d.libopencv_calib3d249d.libopencv_objdetect249d.libopencv_contrib249d.libopencv_legacy249d.libopencv_flann249d.libopencv_nonfree249d.libopencv_ts249d.libopencv_videostab249.lib

配置选择 release

opencv_calib3d249.libopencv_contrib249.libopencv_core249.libopencv_features2d249.libopencv_flann249.libopencv_gpu249.libopencv_highgui249.libopencv_imgproc249.libopencv_legacy249.libopencv_ml249.libopencv_nonfree249.libopencv_objdetect249.libopencv_ocl249.libopencv_photo249.libopencv_stitching249.libopencv_superres249.libopencv_ts249.libopencv_video249.libopencv_videostab249.lib

5.完成后编译链接

 

Opencv + vs2012环境配置