一开学就搞实训,还是没学过的图像处理。痛苦啊!图像处理时一般使用Matlab中的图像工具箱,或者是C/C++和OpenCV结合使用。以前看过一些关于opencv的文章,没想到现在要用上了。
把搭建开发环境的过程分享一下
一、首先假设已经安装了Visual studio 2012 。然后下载 opencv 2.46 ,点击exe解压文件到指定的目录。我的在”E:\Program Files\opencv"目录下。
然后添加环境变量PATH
E:\Program Files\opencv\build\x86\vc11\bin;
E:\Program Files\opencv\build\x86\vc11\lib;
2.打开visual studio 2012,新建win32控制台应用程序,如ImageDisplay如图
3.在ImageDisplay属性页上右键添加包含目录和库目录两项。分别为:
包含目录:
E:\Program Files\opencv\build\include
E:\Program Files\opencv\build\include\opencv
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.保存后,大功告成!运行,就得到阿狸头像啦
附:源代码
// ImageDisplay.cpp : 定义控制台应用程序的入口点。
// #include "stdafx.h"
#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
using namespace cv;
using namespace std;
int main(int argc, _TCHAR* argv[])
{
namedWindow( "show_image", WINDOW_AUTOSIZE );
const char* imagename = "ali.png";
// ali.png保存在ImageDisplay/ImageDispaly下
Mat img = imread( imagename );
if(img.empty())
{
fprintf(stderr, "Can not load image %s\n", imagename);
return -;
}
imshow( "show_image", img );
char c = waitKey();
if( c == )
return ;
}