前言:
lib库:运行库
dev库:开发
gdb库:调试
安装
1.1
OpenCV是一个开源的软件,在一个source文件下,包含了所有的源代码文件。
使用哪种操作系统?windows还是linux?使用哪种编译器?
注意,执行安装包很可能不仅仅安装源文件,还可能安装构建应用程序所需的已编译的二进制文件。检查build目录,它应该包含x64和x86,子目录下有vc10,vc11,vc12等,对应了不同的visual studio的二进制文件。
为了完成安装过程并构建OpenCV二进制文件,你需要实用CMake工具,该工具可从http:cmake.org下载。CMake是另一个开源的软件工具,用于控制使用了跨平台配置文件的软件系统的编译过程。它可以生成在特定环境下编译软件库所需要的makefile和workspace文件。
因此你需要事先下载并安装CMake,之后可以使用命令工具来运行CMake。
在Linux环境下,你可以用make实用命令运行前面生成的makefile文件。为了完成所有的目录的安装,你需要运行Build INSTALL 或者sudo make INSTALL
先安装依赖的包:
参考一篇外文的教程:如下
Compulsory Dependencies
We need CMake to configure the installation, GCC for compilation, Python-devel and Numpy for creating Pythonextensions etc.
yum install cmake
yum install python-devel numpy
yum install gcc gcc-c++
Next we need GTK support for GUI features, Camera support (libdc1394, libv4l), Media Support (ffmpeg, gstreamer)
etc.
yum install gtk2-devel
yum install libdc1394-devel
yum install libv4l-devel
yum install ffmpeg-devel
yum install gstreamer-plugins-base-devel
Optional Dependencies
Above dependencies are sufficient to install OpenCV in your fedora machine. But depending upon your requirements,
you may need some extra dependencies. A list of such optional dependencies are given below. You can either leave itor install it, your call ?
OpenCV comes with supporting files for image formats like PNG, JPEG, JPEG2000, TIFF, WebP etc. But it may be a little old. If you want to get latest libraries, you can install development files for these formats.
yum install libpng-devel
yum install libjpeg-turbo-devel
yum install jasper-devel
yum install openexr-devel
yum install libtiff-devel
yum install libwebp-devel
Several OpenCV functions are parallelized with Intel’s Threading Building Blocks (TBB). But if you want to enable it, you need to install TBB first. ( Also while configuring installation with CMake, don’t forget to pass -DWITH_TBB=ON. More details below.)
yum install tbb-devel
OpenCV uses another library Eigen for optimized mathematical operations. So if you have Eigen installed in your system, you can exploit it. ( Also while configuring installation with CMake, don’t forget to pass -D WITH_EIGEN=ON.More details below.)
yum install eigen3-devel
If you want to build documentation ( Yes, you can create offline version of OpenCV’s complete official documentation in your system in HTML with full search facility so that you need not access internet always if any question, and it is quite FAST!!! ), you need to install Sphinx (a documentation generation tool) and pdflatex (if you want to create
a PDF version of it). ( Also while configuring installation with CMake, don’t forget to pass -D BUILD_DOCS=ON.More details below.)
yum install python-sphinx
yum install texlive
下载opencv压缩包
下载.zip或者.git的opencv文件
cmake编译,安装
-
进入你下在解压好的opencv中
-
新建文件夹mkdir build
-
进入build目录
-
Set installation path and build type : cmake -D CMAKE_BUILD_TYPE=Release -D CMAKE_INSTALL_PREFIX=/usr/local
.
.
..
..
It specifies that build type is “Release Mode” and installation path is /usr/local. Observe the -D before each option and … at the end. In short, this is the format:
cmake [-D ] [-D ] …
You can specify as many flags you want, but each flag should be preceded by -D.
你也可以安装额外的功能:比如TBB,documentation,GPU等等
- Enable TBB and Eigen support:
cmake -D WITH_TBB=ON -D WITH_EIGEN=ON
.
.
..
..
- Enable documentation and disable tests and samples
cmake -D BUILD_DOCS=ON -D BUILD_TESTS=OFF
-D BUILD_PERF_TESTS=OFF -D BUILD_EXAMPLES=OFF
.
.
..
..
- Disable all GPU related modules.
cmake -D WITH_OPENCL=OFF -D WITH_CUDA=OFF
-D BUILD_opencv_gpu=OFF -D BUILD_opencv_gpuarithm=OFF
-D BUILD_opencv_gpubgsegm=OFF -D BUILD_ opencv_gpucodec=OFF
-D BUILD_opencv_gpufeatures2d=OFF -D BUILD_opencv_gpufilters=OFF
-D BUILD_opencv_gpuimgproc=OFF -D BUILD_opencv_gpulegacy=OFF
-D BUILD_opencv_gpuoptflow=OFF -D BUILD_opencv_gpustereo=OFF
-D BUILD_opencv_gpuwarping=OFF
.
.
..
..
- Set installation path and build type
cmake -D CMAKE_BUILD_TYPE=RELEASE
-D CMAKE_INSTALL_PREFIX=/usr/local
.
.
..
..
-
make
-
make install
移动可执行文件
su mv /usr/local/lib/python2.7/site-packages/cv2.so /usr/lib/python2.7/→site-packages
1.2
安装Contrib模块
有些模块包含在称为opencv_contrib的资源库中,他们可以在https://github.com/Itseez/opencv_contrib下载,这与Opencv不同。强烈建议安装这些模块,因为他们含有Opencv没有的功能,例如人脸识别等。
下载完成之后(无论是zip还是git,推荐使用git,可以用git pull命令来获取),需要重新运行如下的cmake命令,该命令可生成带opencv_contrib模块的Opencv项目:
cmake -DOPENCV_EXTRA_MODULES_PATH = <opencv_contrib>/modules <opencv_source_directory>
如果已经按照标准流程进行安装并在下载opencv的文件夹下创建一个build文件夹,然后运行下面的命令:
mkdir build && cd build
cmake -D CMAKE_BUILD_TYPE = Release -DOPENCV_EXTRA_MODULES_PATH = <opencv_contrib>/modules -D CMAKE_INSTALL_PREFIX = /usr/local ..
make
如果扩展库文件不能用,考虑安装3.4.2.16版本的opencv-python和opencv-contrib-pyhton的库
实现原理
常用的模块:
- opencv_core模块,包含了程序库的核心功能,特别是基本的数据结构和算法函数
- opencv_imgproc模块,包含了主要的图像处理函数。
- opencv_highgui模块,包含图像,视频读写函数和部分用户界面函数
- opencv_features2d模块,包含特征点检测器,描述子以及特征点匹配框架
- opencv_calib3d模块,包含相机标定,双视角几何估计以及立体函数
- opencv_video模块,包含运动估计,特征跟踪以及前景提取函数和类
- opencv_objdectect模块,包含目标检测函数,例如面部和人体探测器
所有的这些模块都有一个对应的头文件(位于include文件夹下)。因此,典型的OpenCV C++代码会首先包含必须的模块。例如:
- include <opencv2/core/core.hpp>
- include <opencv2/imgproc/imgproc.hpp>
- include <opencv2/higgui/higgui.hpp>
错误
参考的opencv的一个社区里的解决方案
错误如下
CMake Error at cmake/OpenCVDetectCXXCompiler.cmake:85 (list):
list GET given empty list
Call Stack (most recent call first):
CMakeLists.txt:68 (include)
CMake Error at cmake/OpenCVDetectCXXCompiler.cmake:86 (list):
list GET given empty list
Call Stack (most recent call first):
CMakeLists.txt:68 (include)
CMake Error at cmake/OpenCVDetectCXXCompiler.cmake:89 (math):
math cannot parse the expression: "*100 + ": syntax error, unexpected
exp_TIMES, expecting exp_PLUS or exp_MINUS or exp_OPENPARENT or exp_NUMBER
(1)
Call Stack (most recent call first):
CMakeLists.txt:68 (include)
-- Detected version of GNU GCC: ()
解决方案如下
https://github.com/opencv/opencv/pull/9430/files
sir, this error puzzled me for some hours and i found this github page. i will take OpenCV2.4.13 as example, in file opencv2.4.13/cmake/ OpenCVDetectCXXCompiler.cmake, u have to change “dumpversion” to “dumpfullversion”
explanation is that in gcc with higher version, dumpversion function can’t get true full version number of compiler so that cmake progress will fail.