1. 下载opencv 2.4.6,解压即可
2. 安装好vs2012 ultimate
3.适当的配置好环系统环境和vs配置就好了
(1)系统环境:
a.将
M:\Develop\opencv\build\x86\vc11\bin其中opencv前面的串是你放置opencv文件所在的位置
加入到环境变量中。若通过GUI界面设置PATH,则为及时生效,不用注销
b. 将下面两个文件 (在 opencv\build\x86\vc11\bin 下) 复制到系统文件夹c:\windows\system32下:
opencv_core246d.dll
opencv_highgui246d.dll
(2)vs配置
通过属性管理器配置,可以达到配置复用的目的。
具体可参考
http://www.cnblogs.com/9keyes/archive/2012/08/05/2624000.html
想想还是补上后面的操作吧,不过现在用的是vs2010ultimate了。大同小异。右键点击项目名->Properties。
首先是头文件,在VC++ Directories,点击后在右边的include directories处填下你的opencv包里面的include目录,如下共三个:
L:\Develop\opencv\build\\include;
L:\Develop\opencv\build\include\opencv;
L:\Develop\opencv\build\include\opencv2;
注意是build下的include,而不是opencv下的include,我某次配不小心配成了后者,弄好好久不行才发现是这样!
然后是静态库,也是在VC++ Directories,点击后在右边的library directories填下你的opencv包里面的lib目录,类似的如下:
L:\Develop\opencv\build\x86\vc10\lib
然后是动态库,因为我们不知道那些lib会动态链接,所以我们还是把上面的lib目录里面的东西全部拉进来,注意每一个lib都对应另一个名字相同但后面加了个d字母的lib(如opencv_calib3d246.lib和opencv_calib3d246d.lib),这两个分别对应debug和release模式,d结尾即是debug模式。我们右键点击项目名字进入Properties,这个是debug模式下的属性配置。如果你想release模式也能运行的话就要同样步骤只不过这些动态包换成release版本的。
Linker->Input,在Additional Dependencies处加入以下:
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
保存应用以上的设置变动,用一下代码测试:
#include <cv.h>
#include <highgui.h>
int main ( int argc, char **argv )
{
cvNamedWindow( "My Window", 1 );
IplImage *img = cvCreateImage( cvSize( 240, 120 ), IPL_DEPTH_8U, 1 );
CvFont font;
double hScale = 1.0;
double vScale = 1.0;
int lineWidth = 3;
cvInitFont( &font, CV_FONT_HERSHEY_SIMPLEX | CV_FONT_ITALIC,
hScale, vScale, 0, lineWidth );
cvPutText( img, "Hello World!", cvPoint( 20, 40 ), &font,
cvScalar( 255, 255, 0 ) );
cvShowImage( "My Window", img );
cvWaitKey();
return 0;
}
运行结果如下: