Opencv的配置常识学习整理

13 篇文章 0 订阅
11 篇文章 0 订阅
本文详细介绍了OpenCV的配置知识,特别是CMake的用途和功能,包括CMakeLists.txt的编写,以及如何用CMake创建和管理OpenCV工程。此外,还提及了OpenCV各个文件夹的含义,如3rdparty、data、include等,帮助读者更好地理解和使用OpenCV。
摘要由CSDN通过智能技术生成

 

opencv的概述:

http://www.opencv.org.cn/index.php/OpenCV%E6%A6%82%E8%BF%B0#.E9.87.8D.E8.A6.81.E7.89.B9.E6.80.A7

 

推荐参考资料《opencv基础篇》和《学习Opencv》,这两本Opencv讲的知识点都不是很细,但是可以作为参考手册,真正需要看的是Opencv教程,这个在高版本的Opencv的安装好的目录下的doc文件夹目录下都有的,名字一般是opencv_tutorials。按照这里的教程一个个做下去,不懂的地方参考上面两本书和网上百度维基,你会收获很大。另外OpenCV.2.Computer.Vision.Application.Programming.Cookbook这本书也很不错。对于opencv的新的C++接口的Mat讲的很好。(笔者建议要学就学最新的,跟上潮流,Iplimage貌似已经过时,因为运用不当的内存泄露)

对于高版本的Opencv安装网上有很多教程这里不再赘述。下面简要的介绍各个相关知识(肯定会有不足的地方还望各位补充):

CMake

许多人安装Opencv稀里糊涂的就安装了Cmake,但是不知道所以然。笔者记录一下Cmake的功效:

CMake是一个跨平台的安装(编译)工具,可以用简单的语句来描述所有平台的安装(编译过程)。他能够输出各种各样的makefile或者project文件,能测试编译器所支持的C++特性,类似UNIX下的automake。只是 CMake 组态档取名为 CmakeLists.txtCmake 并不直接建构出最终的软件,而是产生标准的建构档(如 Unix Makefile Windows Visual C++ projects/workspaces),然后再依一般的建构方式使用。这使得熟悉某个集成开发环境IDE)的开发者可以用标准的方式建构他的软件,这种可以使用各平台的原生建构系统的能力是 CMake SCons 等其他类似系统的区别之处。

  cmake和vs2008

CMake 可以编译源代码、制作程式库、产生适配器(wrapper)、还可以用任意的顺序建构执行档CMake 支援 in-place 建构(二进档和源代码在同一个目录树中)和 out-of-place 建构(二进档在别的目录里),因此可以很容易从同一个源代码目录树中建构出多个二进档。CMake 也支持静态与动态程式库的建构。

“CMake”这个名字是“cross platform make”的缩写。虽然名字中含有“make”,但是CMakeUnix上常见的“make”系统是分开的,而且更为高阶。

CMake是为了解决美国国家医学图书馆出资的Visible Human Project专案下的Insight Segmentation and Registration Toolkit ITK软件的跨平台建构的需求而创造出来的,其设计受到了Ken Martin开发的pcmaker所影响。pcmaker当初则是为了支援Visualization Toolkit这个开放源代码的三维图形和视觉系统才出现的,今日VTK也采用了CMake。在设计CMake之时,Kitware公司的Bill Hoffman采用了pcmaker的一些重要想法,加上更多他自己的点子,想把GNU建构系统的一些功能整合进来。CMake最初的实作是在2000年中作的,在2001年初有了急速的进展,许多改良是来自其他把CMake整合到自己的系统中的开发者,比方说,采用CMake作为建构环境的VXL社群就贡献了很多重要的功能,Brad King为了支援CABLEGCC-XML这套自动包装工具也加了几项功能,奇异公司的研发部门则用在内部的测试系统DART,还有一些功能是为了让VTK可以过渡到CMake和支援(美国Los Alamos国家实验室”&“洛斯阿拉莫斯国家实验室)的Advanced Computing Lab的平行视觉系统ParaView而加的。

功能介绍

组态档是用一种建构软件专用的特殊编程语言写的CMake脚本

内建C语言、C++FortranJava的自动相依性分析功能。

经由CMake脚本语言支援SWIGQtFLTK

内建对微软Visual Studio .NET和过去的Visual Studio版本的支援,可以产生后缀为.dsp.sln.vcproj的文档。

用传统的时间标签侦测档案内容的改变。

支援平行建构(在多台电脑上同时建构)

在许多操作系统上进行跨平台编译,包括LinuxPOSIX相容的系统(AIX*BSDHP-UXIRIXMinGW/MSYSSolaris系统)、Mac OS X微软Windows 95/98/NT/2000/XP等。

产生可以给Graphviz用的全局相依图。

已经和DartCTestCPack等软件测试和释出的工具整合。

应用软件

Bullet Physics Engine

KDE (starting with version 4)

The Visualization Toolkit (VTK)

Insight Segmentation and Registration Toolkit (ITK)

ParaView

DevIL - Open Image Library

OpenSceneGraph

Scribus

Drishti

PvPGN

Chicken

ParadisEO

Quantum GIS

OPENCV

PCL

Fast Light Toolkit(FLTK)

MySql 5.58版本以后

安装

下载cmake

win版本安装直接运行EXE

LINUX版本的安装:

安装cmake

cmake-*.*.*tar.gz为下载下来的源码包

tar xvf cmake-*.*.*.tar.gz

cd cmake-*.*.*

./bootstrap

make

make install

如果已经安装了cmake,想要安装新版本,:

cd cmake-*.*.*

cmake .

make

make install

所以Cmake可用可不用,不用的话自己编译也可以看opencv的源码,但是Cmake相当于一键编译,不用自己那么麻烦了。

opencv2.1开始,可以使用CMake来创建和管理opencv工程了。

CMake 是一个跨平台、开源的编译系统,用来控制我们的编译过程。

cmakeopencv创建一个有main.c的工程,我们需要先创建一个CMakeLists.txt

在这个文件中,定义了编译顺序和先决条件。

步骤如下:

1      创建一个工程

PROJECT(project_name)

假设在我们的工程中,要使用到opencv库,那么,就要定义它。这里使用REQUIRED语句来定义。

FIND_PACKAGE(OpencvREQUIRED)

(2)需要定义可执行文件的名字,和依赖文件等。在我们这个实例中,只有main.c一个文件,所以,我们就简单的把工程的名字,作为可执行文件的名字。工程的名字是存储在${PROJECT_NAME}变量中的。

ADD_EXECUTABLE{${PROJECT_NAME}main.c}

(3)需要将opencv的库文件链接到程序中。链接的语句是TARGET_LINK_LIBRARIES,当然,还要写明是链接到哪个工程。代码如下:

TARGET_LINK_LIBRARIES(${PROJECT_NAME}${Opencv_LIBS})

(4)CMakeLists.txt文件写好之后,就可以开始编译我们的工程了

其他的一些信息:

如果你想查看Opencv的版本,代码如下:

IF(${OpenCV_VERSION} VERSION_LESS 2.0.0)

MESSAGE(FATAL_ERROR“OpenCV version is not compatible : ${OpenCV_VERSION}”)

ENDIF()

参考网址:

http://baike.baidu.com/view/1126160.htm

http://www.opencvchina.com/thread-123-1-1.html

关于VS配置OpencvTBB加速的,可以参考网址(需要注册新浪微博,要不图片即使点击也会看不到):

http://www.cnblogs.com/yinxiangpei/articles/2388328.html

Opencv各个文件夹含义

其实最简单的方法想理解各个文件夹的含义(通用性方法)就是看每个文件夹中的readme文本,一个优秀的平台都会有良好的记录,Intel也不例外,我只是进行了相应的整合和归纳:

3rdparty文件夹

主观感觉是与第三方有关的一个文件夹,readme中介绍:

这个文件夹包含highgui模块的库和几个非常受欢迎的静态图像编解码器。

This folder contains libraries and headers of a few very popular still image codecs used by highgui module.The libraries and headers are preferably to build Win32 and Win64 versions of OpenCV.On UNIX systems all the libraries are automatically detected by configure script.In order to use these versions of libraries instead of system ones on UNIX systems you should use BUILD_<library_name> CMake flags (for example, BUILD_PNG for the libpng library).

------------------------------------------------------------------------------------
libjpeg 8d (8.4)  -   The Independent JPEG Group's JPEG software.
                      Copyright (C) 1991-2012, Thomas G. Lane, Guido Vollbeding.
                      See IGJ home page
http://www.ijg.org
                      for details and links to the source code

                      HAVE_JPEG preprocessor flag must be set to make highgui use libjpeg.
                      On UNIX systems configure script takes care of it.
------------------------------------------------------------------------------------
libpng 1.5.12     -   Portable Network Graphics library.
                      Copyright (c) 2004, 2006-2012 Glenn Randers-Pehrson.
                      See libpng home page
http://www.libpng.org
                      for details and links to the source code

                      HAVE_PNG preprocessor flag must be set to make highgui use libpng.
                      On UNIX systems configure script takes care of it.
------------------------------------------------------------------------------------
libtiff 4.0.2     -   Tag Image File Format (TIFF) Software
                      Copyright (c) 1988-1997 Sam Leffler
                      Copyright (c) 1991-1997 Silicon Graphics, Inc.
                      See libtiff home page
http://www.remotesensing.org/libtiff/
                      for details and links to the source code

                      HAVE_TIFF preprocessor flag must be set to make highgui use libtiff.
                      On UNIX systems configure script takes care of it.
                      In this build support for ZIP (LZ77 compression) is turned on.
------------------------------------------------------------------------------------
zlib 1.2.7        -   General purpose LZ77 compression library
                      Copyright (C) 1995-2012 Jean-loup Gailly and Mark Adler.
                      See zlib home page
http://www.zlib.net
                      for details and links to the source code

                      No preprocessor definition is needed to make highgui use this library -
                      it is included automatically if either libpng or libtiff are used.
------------------------------------------------------------------------------------
jasper-1.900.1    -   JasPer is a collection of software
                      (i.e., a library and application programs) for the coding
                      and manipulation of images.  This software can handle image data in a
                      variety of formats.  One such format supported by JasPer is the JPEG-2000
                      format defined in ISO/IEC 15444-1.
            
                      Copyright (c) 1999-2000 Image Power, Inc.
                      Copyright (c) 1999-2000 The University of British Columbia
                      Copyright (c) 2001-2003 Michael David Adams

                      The JasPer license can be found in src/libjasper.
            
                      OpenCV on Windows uses pre-built libjasper library
                      (lib/libjasper*). To get the latest source code,
                      please, visit the project homepage:
                     
http://www.ece.uvic.ca/~mdadams/jasper/
------------------------------------------------------------------------------------
openexr-1.7.1     -   OpenEXR is a high dynamic-range (HDR) image file format developed
                      by Industrial Light & Magic for use in computer imaging applications.

                      Copyright (c) 2006, Industrial Light & Magic, a division of Lucasfilm
                      Entertainment Company Ltd. Portions contributed and copyright held by
                      others as indicated. All rights reserved.

                      The project homepage: http://www.openexr.com
------------------------------------------------------------------------------------
ffmpeg-0.8.0      -   FFmpeg is a complete, cross-platform solution to record,
                      convert and stream audio and video. It includes libavcodec -
                      the leading audio/video codec library, and also libavformat, libavutils and
                      other helper libraries that are used by OpenCV (in highgui module) to
                      read and write video files.

                      The project homepage: http://ffmpeg.org/
------------------------------------------------------------------------------------

 

android文件夹

主观感觉与android系统有关,对于VS开发影响不大不理会,这里没有readme.txt

apps文件夹

关于harr训练的一些文件

built文件夹

在配置Opencv会用到,内部还有x86x64不同配置目录和相应的include的头文件和库文件,以及不同平台的设置VC/python

data文件夹

这个文件夹包含了cv库和一些demo应用例程的大量数据

This folder contains various data that is used by cv libraries and/or demo applications.

----------------------------------------------------------------------------------------

 

haarcascades - the folder contains trained classifiers for detecting objects

               of a particular type, e.g. faces (frontal, profile), pedestrians etc.

               Some of the classifiers have a special license - please,

               look into the files for details.

doc文件夹

一些文档文件包括介绍、教程、图片、cv图标、.py的脚本(Python 的缩写,具有脚本语言中最丰富和强大的类库,足以支持绝大多数日常应用。在Symbina智能手机上支持C++JAVA开发的两类程序,装上Python后,也就可以支持众多以Python开发的各种程序了。

)、java脚本之类的,其中有与上述目录中重复的文档,这是opencv归纳不好的地方。总之感觉总doc文件夹里很乱,看教程还不如去built中的doc文件夹中找。

include文件夹

opencv基础配置相关,你会看到很多例程中利用了#include<opencv2/opencv.hpp>就是与此相关

ios文件夹

不言而喻,苹果操作系统的平台

Assuming that your build directory is on the same level that opencv source,

From the build directory run

  ../opencv/ios/configure-device_xcode.sh

or

  ../opencv/ios/configure-simulator_xcode.sh

 

Then from the same folder invoke

 

xcodebuild -sdk iphoneos -configuration Release -target ALL_BUILD

xcodebuild -sdk iphoneos -configuration Release -target install install

 

or

 

xcodebuild -sdk iphonesimulator -configuration Release -target ALL_BUILD

xcodebuild -sdk iphonesimulator -configuration Release -target install install

modules文件夹

这里可是各类模板的聚居地。也是大部分源码的所在,如果你新接触编程,一定很诧异每次go to defination都到不了源码的所在,是因为opencv已经把源码封装成库,你每次调用的是libdll文件而不是这些.cpp。但是你用Cmake就可以导出源码,自行查看源码了。

例如,core文件夹下就包含了基本数据类型的定义,imgproc文件夹下包含了常用的数字图像处理函数源代码:如cvCanny()cvSobel()可参考网址:

http://blog.sina.com.cn/s/blog_5e8715490101fjed.html

samples文件夹

一些opencv自带的例子包括人脸检测、相机标定、匹配等等。

先归纳这么多,以后学习了解了再进行总结归纳。还望各位多多指出不足和错误。

另外,推荐网址:

CV codes代码分类整理合集 

http://www.sigvc.org/bbs/forum.php?mod=viewthread&tid=72

 

 

评论 4
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值