OpenCV 第一课(安装与配置)
Posted 一只有恒心的小菜鸟
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了OpenCV 第一课(安装与配置)相关的知识,希望对你有一定的参考价值。
OpenCV 第一课(安装与配置)
下载安装软件
官网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
后来发现是因为网速的原因下载的包总是不全,虽然无论下载多少图标显示都是一样的,但一定要注意下载后的大小是不是和网上安装包大小一样,以确定你下的包完整。
配置环境变量
win10 专业版,系统 -> 高级系统设置 -> 环境变量.
在用户变量中新建变量: opencv, 变量值 : D:\Program Files\opencv\build
在用户变量中选择"path"(不区分大小写),点击“编辑”,在其末尾添加 ‘;D\Program Files\opencv\build\x86\vc12\bin‘,这里分号不能省略
如果用户变量中没有"path",则新建变量:"path",变量值:‘D:\Program Files\opencv\build\x86\vc12\bin‘
注:无论你是64位还是32位系统,上面路径都使用x86
至此环境变量配置完毕。此时需重启电脑或注销电脑,使环境变量生效。
编写属性表
打开记事本,分别创建两个文本"opencvdebug.props"和"opencvrelease.props",其中对应的内容如下,可以直接拷贝过去,但注意其中‘IncludePath’和“LibraryPath”中的“D:\Program Files”要修改为自己opencv安装路径。
debug版本
- <?xml version="1.0" encoding="utf-8"?>
- <Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
- <ImportGroup Label="PropertySheets" />
- <PropertyGroup Label="UserMacros" />
- <PropertyGroup>
- <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>
- <LibraryPath>D:\Program Files\opencv\build\x86\vc12\lib;$(LibraryPath)</LibraryPath>
- </PropertyGroup>
- <ItemDefinitionGroup>
- <Link>
- <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>
- </Link>
- </ItemDefinitionGroup>
- <ItemGroup />
- </Project>
release版本
- <?xml version="1.0" encoding="utf-8"?>
- <Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
- <ImportGroup Label="PropertySheets" />
- <PropertyGroup Label="UserMacros" />
- <PropertyGroup>
- <IncludePath>D:\Program Files\opencv\build\include;D:\Program Files\opencv\build\include\opencv;D:\Program Files\opencv\build\include\opencv2;$(IncludePath)</IncludePath>
- <LibraryPath>D:\Program Files\opencv\build\x86\vc12\lib;$(LibraryPath)</LibraryPath>
- </PropertyGroup>
- <ItemDefinitionGroup>
- <Link>
- <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>
- </Link>
- </ItemDefinitionGroup>
- <ItemGroup />
- </Project>
配置VS2013
打开VS2013,文件 -> 新建 -> 项目,新建控台应用程序test
分别添加上两步创建的属性表
此处添加"opencvdebug.props"
此处添加"opencvrelease.props"
OK,VS2013现在就配置好了,写一个例子试验一下
测试
在源文件写入下面代码,你可以复制过去
- #include<cv.h>
- #include<highgui.h>
- int main(int argc, char** argv[])
- {
- IplImage* src = cvLoadImage("F:\\Programming\\C#\\Others\\test\\test\\timg.jpg", CV_LOAD_IMAGE_GRAYSCALE);
- cvNamedWindow("Src", CV_WINDOW_AUTOSIZE);
- cvShowImage("Src", src);
- cvWaitKey(0);
- cvReleaseImage(&src);
- cvDestroyAllWindows();
- return 0;
- }
其中图片路径自己选择。
结果:
之后再每次使用opencv创建工程之后分别将上述两个属性表导入就可以了。
以上是关于OpenCV 第一课(安装与配置)的主要内容,如果未能解决你的问题,请参考以下文章
网络爬虫学习小组·第一课 | Python安装基本语法与JupyterLab代码编辑器配置
Python 基础 2022 最新第一课 安装 & 环境配置