首页 > 代码库 > OpenCV 第一课(安装与配置)

OpenCV 第一课(安装与配置)

OpenCV 第一课(安装与配置)

win10,opencv-2.4.13, 安装, vs2013, 配置

下载安装软件

官网OpenCV下载地址下载最新版本,我下载的是opencv.2.4.13,然后解压安装,我写的路径是D:\Program Files。注意本文中绿色标注的要换成你自己的安装路径。

这里得说一点,可能是因为网速太差的原因,昨天晚上下载了几次安装时都提示说“cannott open file‘opencv-2.4.13.exe‘ as archive”。我当时一直不明白是怎么回事,网上中文说这个原因的几乎没有,可能大家觉得这种问题不是问题吧。
Sign up
OpenCV Windows install: can not open file “OpenCV-2.4.5.exe” as archive

后来发现是因为网速的原因下载的包总是不全,虽然无论下载多少图标显示都是一样的,但一定要注意下载后的大小是不是和网上安装包大小一样,以确定你下的包完整。

VS2013下载地址

配置环境变量

win10 专业版,系统 -> 高级系统设置 -> 环境变量.

技术分享

1474633893393.jpg

技术分享

1474633913875.jpg

技术分享

1474633980828.jpg

在用户变量中新建变量: opencv, 变量值 : D:\Program Files\opencv\build

技术分享

1474634262623.jpg

在用户变量中选择"path"(不区分大小写),点击“编辑”,在其末尾添加 ‘;D\Program Files\opencv\build\x86\vc12\bin‘,这里分号不能省略
如果用户变量中没有"path",则新建变量:"path",变量值:‘D:\Program Files\opencv\build\x86\vc12\bin‘

技术分享

1474634567991.jpg

注:无论你是64位还是32位系统,上面路径都使用x86

至此环境变量配置完毕。此时需重启电脑或注销电脑,使环境变量生效。

编写属性表

打开记事本,分别创建两个文本"opencvdebug.props"和"opencvrelease.props",其中对应的内容如下,可以直接拷贝过去,但注意其中‘IncludePath’和“LibraryPath”中的“D:\Program Files”要修改为自己opencv安装路径。

  • debug版本

  1. <?xml version="1.0" encoding="utf-8"?> 
  2. <Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> 
  3. <ImportGroup Label="PropertySheets" /> 
  4. <PropertyGroup Label="UserMacros" /> 
  5. <PropertyGroup> 
  6. <IncludePath>D:\Program Files\opencv\build\include\opencv\build\include;D:\Program Files\opencv\build\include\opencv\build\include\opencv\build\include\opencv;D:\Program Files\opencv\build\include\opencv2;$(IncludePath)</IncludePath> 
  7. <LibraryPath>D:\Program Files\opencv\build\x86\vc12\lib;$(LibraryPath)</LibraryPath> 
  8. </PropertyGroup> 
  9. <ItemDefinitionGroup> 
  10. <Link> 
  11. <AdditionalDependencies>opencv_ml2413d.lib;opencv_calib3d2413d.lib;opencv_contrib2413d.lib;opencv_core2413d.lib;opencv_features2d2413d.lib;opencv_flann2413d.lib;opencv_gpu2413d.lib;opencv_highgui2413d.lib;opencv_imgproc2413d.lib;opencv_legacy2413d.lib;opencv_objdetect2413d.lib;opencv_ts2413d.lib;opencv_video2413d.lib;opencv_nonfree2413d.lib;opencv_ocl2413d.lib;opencv_photo2413d.lib;opencv_stitching2413d.lib;opencv_superres2413d.lib;opencv_videostab2413d.lib;%(AdditionalDependencies)</AdditionalDependencies> 
  12. </Link> 
  13. </ItemDefinitionGroup> 
  14. <ItemGroup /> 
  15. </Project> 
  • release版本

  1. <?xml version="1.0" encoding="utf-8"?> 
  2. <Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> 
  3. <ImportGroup Label="PropertySheets" /> 
  4. <PropertyGroup Label="UserMacros" /> 
  5. <PropertyGroup> 
  6. <IncludePath>D:\Program Files\opencv\build\include;D:\Program Files\opencv\build\include\opencv;D:\Program Files\opencv\build\include\opencv2;$(IncludePath)</IncludePath> 
  7. <LibraryPath>D:\Program Files\opencv\build\x86\vc12\lib;$(LibraryPath)</LibraryPath> 
  8. </PropertyGroup> 
  9. <ItemDefinitionGroup> 
  10. <Link> 
  11. <AdditionalDependencies>opencv_objdetect2413.lib;opencv_ts2413.lib;opencv_video2413.lib;opencv_nonfree2413.lib;opencv_ocl2413.lib;opencv_photo2413.lib;opencv_stitching2413.lib;opencv_superres2413.lib;opencv_videostab2413.lib;opencv_calib3d2413.lib;opencv_contrib2413.lib;opencv_core2413.lib;opencv_features2d2413.lib;opencv_flann2413.lib;opencv_gpu2413.lib;opencv_highgui2413.lib;opencv_imgproc2413.lib;opencv_legacy2413.lib;opencv_ml2413.lib;%(AdditionalDependencies)</AdditionalDependencies> 
  12. </Link> 
  13. </ItemDefinitionGroup> 
  14. <ItemGroup /> 
  15. </Project> 

配置VS2013

打开VS2013,文件 -> 新建 -> 项目,新建控台应用程序test

技术分享

1474634781916.jpg

分别添加上两步创建的属性表

技术分享

1474635625690.jpg

技术分享

1474635448340.jpg

此处添加"opencvdebug.props"

技术分享

1474635513018.jpg

此处添加"opencvrelease.props"

OK,VS2013现在就配置好了,写一个例子试验一下

测试

在源文件写入下面代码,你可以复制过去

  1. #include<cv.h> 
  2. #include<highgui.h> 
  3. int main(int argc, char** argv[]) 

  4. IplImage* src = http://www.mamicode.com/cvLoadImage("F:\\Programming\\C#\\Others\\test\\test\\timg.jpg", CV_LOAD_IMAGE_GRAYSCALE); 
  5. cvNamedWindow("Src", CV_WINDOW_AUTOSIZE); 
  6. cvShowImage("Src", src); 
  7. cvWaitKey(0); 
  8. cvReleaseImage(&src); 
  9. cvDestroyAllWindows(); 
  10. return 0

其中图片路径自己选择。

结果:

技术分享

1474635736652.jpg

之后再每次使用opencv创建工程之后分别将上述两个属性表导入就可以了。

OpenCV 第一课(安装与配置)