1、下载解压opencv
2、设置环境变量
在打开用户的Path变量,在后面添加
vs2013对应添加:E:\PF\opencv\build\x86\vc12\bin; vs2012对应添加:E:\PF\opencv\build\x86\vc11\bin; vs2010对应添加:E:\PF\opencv\build\x86\vc10\bin;
3、设置vs2013
新建一个控制台程序
选择属性管理,如下图
3.1首先打开Debug下的Microsoft.Cpp.Win32.user
在vc++目录选项,添加头文件目录及其库目录,可以参考下图
添加完成后,找到连接器--输入选项添加库文件
opencv_calib3d2410d.lib; opencv_contrib2410d.lib; opencv_core2410d.lib; opencv_features2d2410d.lib; opencv_flann2410d.lib; opencv_gpu2410d.lib; opencv_highgui2410d.lib; opencv_imgproc2410d.lib; opencv_legacy2410d.lib; opencv_ml2410d.lib; opencv_nonfree2410d.lib; opencv_objdetect2410d.lib; opencv_ocl2410d.lib; opencv_photo2410d.lib; opencv_stitching2410d.lib; opencv_superres2410d.lib; opencv_ts2410d.lib; opencv_video2410d.lib; opencv_videostab2410d.lib;
点击保存即可。
3.2首先打开Release下的Microsoft.Cpp.Win32.user
连接器--输入选项添加库文件
把里面的lib修改成以下即可
opencv_calib3d2410.lib; opencv_contrib2410.lib; opencv_core2410.lib; opencv_features2d2410.lib; opencv_flann2410.lib; opencv_gpu2410.lib; opencv_highgui2410.lib; opencv_imgproc2410.lib; opencv_legacy2410.lib; opencv_ml2410.lib; opencv_nonfree2410.lib; opencv_objdetect2410.lib; opencv_ocl2410.lib; opencv_photo2410.lib; opencv_stitching2410.lib; opencv_superres2410.lib; opencv_ts2410.lib; opencv_video2410.lib; opencv_videostab2410.lib;
4、测试程序
在main.pp添加下面代码
#pragma once#pragma execution_character_set("utf-8") #include <iostream> #include "cv.h" #include "highgui.h" using namespace std; using namespace cv; int main() { IplImage *img = cvLoadImage("D:\\1.jpg",-1); if (img==NULL) { cout << "shibai"; return -1; } cvNamedWindow("showimg", CV_WINDOW_AUTOSIZE); cvShowImage("showimg",img); cvWaitKey(0); cvReleaseImage(&img); cvDestroyWindow("showimg"); return 0; }
运行的时候会提示以下错误信息:
1>------ 已启动全部重新生成: 项目: testopencv, 配置: Debug Win32 ------ 1> main.cpp 1>e:\pf\opencv\build\include\opencv2\flann\logger.h(66): error C4996: ‘fopen‘: This function or variable may be unsafe. Consider using fopen_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details. 1> e:\pf\microsoft visual studio 12.0\vc\include\stdio.h(211) : 参见“fopen”的声明 ========== 全部重新生成: 成功 0 个,失败 1 个,跳过 0 个 ==========
这时需要重新打开属性管理的Debug下的Microsoft.Cpp.Win32.user
找到下图对应位置添加以下代码
WIN32 _DEBUG _CONSOLE _CRT_SECURE_NO_WARNINGS
再重新执行即可成功
时间: 2024-10-27 13:17:40