opencv 2.46与visual studio 2012 配置方法
一开学就搞实训,还是没学过的图像处理。痛苦啊!图像处理时一般使用Matlab中的图像工具箱,或者是C/C++和OpenCV结合使用。以前看过一些关于opencv的文章,没想到现在要用上了。
把搭建开发环境的过程分享一下
一、首先假设已经安装了Visual studio 2012 。然后下载 opencv 2.46 ,点击exe解压文件到指定的目录。我的在”E:\Program Files\opencv"目录下。
然后添加环境变量PATH
1 E:\Program Files\opencv\build\x86\vc11\bin; 2 E:\Program Files\opencv\build\x86\vc11\lib;
2.打开visual studio 2012,新建win32控制台应用程序,如ImageDisplay如图
3.在ImageDisplay属性页上右键添加包含目录和库目录两项。分别为:
包含目录:
1 E:\Program Files\opencv\build\include 2 E:\Program Files\opencv\build\include\opencv 3 E:\Program Files\opencv\build\include\opencv2
库目录:
E:\Program Files\opencv\build\x86\vc11\lib
如下图所示:
4.然后点击连接器,添加附加依赖项:配置Debug属性-》链接器-》输入-》附加依赖项
opencv_calib3d246d.lib;opencv_contrib246d.lib;opencv_core246d.lib;opencv_features2d246d.lib;opencv_flann246d.lib;opencv_gpu246d.lib;opencv_haartraining_engined.lib;opencv_highgui246d.lib;opencv_imgproc246d.lib;opencv_legacy246d.lib;opencv_ml246d.lib;opencv_nonfree246d.lib;opencv_objdetect246d.lib;opencv_ocl246d.lib;opencv_photo246d.lib;opencv_stitching246d.lib;opencv_superres246d.lib;opencv_ts246d.lib;opencv_video246d.lib;opencv_videostab246d.lib
4.保存后,大功告成!运行,就得到阿狸头像啦
附:源代码
1 // ImageDisplay.cpp : 定义控制台应用程序的入口点。 2 // 3 4 #include "stdafx.h" 5 #include <opencv2/core/core.hpp> 6 #include <opencv2/highgui/highgui.hpp> 7 using namespace cv; 8 using namespace std; 9 int main(int argc, _TCHAR* argv[]) 10 { 11 namedWindow( "show_image", WINDOW_AUTOSIZE ); 12 const char* imagename = "ali.png"; 13 // ali.png保存在ImageDisplay/ImageDispaly下 14 Mat img = imread( imagename ); 15 if(img.empty()) 16 { 17 fprintf(stderr, "Can not load image %s\n", imagename); 18 return -1; 19 } 20 imshow( "show_image", img ); 21 char c = waitKey(); 22 if( c == 27 ) 23 return 0; 24 }