OpenCV3.4.x version + Opencv_contrib + Ubuntu16.04 installation record

Article Directory

    Preface
        installation
            prerequisite package prior to mounting
                the installation package dependencies
                required for processing packet image
                processing of video packets required
                opencv function optimization
                section dependencies
                optional dependencies
            compiled and installed
            running tests
    installation Command Summary

Foreword

Opencv development so far, it has been the emergence of version 4.0 stable version, but the project, many people still estimated like 3 version, version 4.0 has just come out, and the corresponding learning books has not appeared, so I still like to use 3 version of opencv, and because the development of more than one computer, so sometimes many times opencv need more equipment, but also many pit encountered, and therefore record what, forget the fear of the future, but also a variety of official documents check.
There is a opencv installation guide, found in the official website. I feel pretty good, it is ubuntu16.04, but many configuration, fireworks blinding, and integrated install their own items when the previously compiled successfully, then the combination of the two produced a paper, do not need to like each other, like so many, but I is not we need to install too much, which we saw some blog, if you feel the need to install the installation.
Here is a step by step in accordance with step instructions how to install, and also test the code, the other you do not want to see so much text, copy and paste want direct command-line installation, see Command Summary section.
Installation process

Bloggers in which the installation process, install the sample used is opencv extended version 3.4.1 and its corresponding fact, think, for opencv3.4 other versions of both the installation process is actually the same.
You need to download opencv3.4.1 and opencv_contrib 3.4.1, and then decompress them, these basic commands and actions are not outlined.
Unzip the package to a certain own specified directory, denoted by {Opencv_Origin_Dir}, currently I specify the directory to extract the, / home / tanqiwei / Documents / environment, so {Opencv_Origin_Dir} correspondence is / home / tanqiwei / Documents / environment / opencv-3.4.1

tanqiwei@ubuntu:~/Documents/environment$ pwd
/home/tanqiwei/Documents/environment
tanqiwei@ubuntu:~/Documents/environment$ ls
opencv-3.4.1         opencv_contrib-3.4.1

Essential package before installation

The installation is not very full, I only enough to install some packages on their own into.
Install the necessary libraries, cmake, git, g ++.

sudo apt-get install build-essential
sudo apt-get install cmake git g++

Installation dependencies

Installing some dependencies.

sudo apt-get install libgtk2.0-dev pkg-config libavcodec-dev libavformat-dev libswscale-dev libv4l-dev liblapacke-dev
sudo apt-get install checkinstall yasm libxine2-dev libgstreamer0.10-dev libgstreamer-plugins-base0.10-dev libfaac-dev libmp3lame-dev libtheora-dev
sudo apt-get install libopencore-amrnb-dev libopencore-amrwb-dev libavresample-dev x264 v4l-utils

Desired image processing package

sudo apt-get install libtbb2 libtbb-dev libjpeg-dev libpng-dev libtiff-dev libjasper-dev libdc1394-22-dev

Packet processing required for video

sudo apt-get install libxvidcore-dev libx264-dev ffmpeg

opencv function optimization

sudo apt-get install libatlas-base-dev gfortran

Part dependencies

sudo apt-get install libopencv-dev  libqt4-dev qt4-qmake libqglviewer-dev libsuitesparse-dev libcxsparse3.1.4 libcholmod3.0.6
sudo apt-get install python-dev python-numpy

Optional dependency

sudo apt-get install libprotobuf-dev protobuf-compiler
sudo apt-get install libgoogle-glog-dev libgflags-dev
sudo apt-get install libgphoto2-dev libeigen3-dev libhdf5-dev doxygen

Compiling and Installing

OpenCV source code into the extracted directory, {Opencv_Origin_Dir}, I was /home/tanqiwei/Documents/environment/opencv-3.4.1
my opencv_contrib directory and its sibling, / home / tanqiwei / Documents / environment / opencv_contrib-3.4. 1 were then run under the {Opencv_Origin_Dir} / home / tanqiwei / Documents / environment

mkdir build
cd build
cmake -D CMAKE_BUILD_TYPE=RELEASE -D CMAKE_INSTALL_PREFIX=/usr/local -D INSTALL_C_EXAMPLES=ON -D INSTALL_PYTHON_EXAMPLES=ON -D WITH_TBB=ON -D WITH_V4L=ON -D WITH_QT=ON -D WITH_OPENGL=ON -D OPENCV_EXTRA_MODULES_PATH=../../opencv_contrib-3.4.1/modules -D PYTHON_EXECUTABLE=/usr/bin/python3.5 -D BUILD_EXAMPLES=ON ..

There are too many parameters belong to the category of cmake, I do not describe here, probably represents opencv should be installed where expansion pack where you are, what features need to open.

In fact, the compilation process will find themselves downloading IPPICV, tiny-dnn and so on.

   IPPICV是个链接的免费子库,如果想要禁用IPP加速,CMake的时候,加上-D WITH_IPP=OFF。

In fact, many may be optional and it seems we do not have cmake from the build output, such as java, VTK and so on, to see this type of output below will know, when you just need a corresponding installation, and then modify CMake compiler command, in general, opencv compilation process, will spontaneously go looking for these things.
 

-- Checking for module 'gstreamer-base-1.0'
--   No package 'gstreamer-base-1.0' found
-- Checking for module 'gstreamer-video-1.0'
--   No package 'gstreamer-video-1.0' found
-- Checking for module 'gstreamer-app-1.0'
--   No package 'gstreamer-app-1.0' found
-- Checking for module 'gstreamer-riff-1.0'
--   No package 'gstreamer-riff-1.0' found
-- Checking for module 'gstreamer-pbutils-1.0'
--   No package 'gstreamer-pbutils-1.0' found


-- Could NOT find JNI (missing:  JAVA_AWT_LIBRARY JAVA_JVM_LIBRARY JAVA_INCLUDE_PATH JAVA_INCLUDE_PATH2 JAVA_AWT_INCLUDE_PATH)
-- Could NOT find Pylint (missing:  PYLINT_EXECUTABLE)
-- Could NOT find Matlab (missing:  MATLAB_MEX_SCRIPT MATLAB_INCLUDE_DIRS MATLAB_ROOT_DIR MATLAB_LIBRARIES MATLAB_LIBRARY_DIRS MATLAB_MEXEXT MATLAB_ARCH MATLAB_BIN)
-- VTK is not found. Please set -DVTK_DIR in CMake to VTK build directory, or to VTK install subdirectory with VTKConfig.cmake file

-- No preference for use of exported gflags CMake configuration set, and no hints for include/library directories provided. Defaulting to preferring an installed/exported gflags CMake configuration if available.
-- Failed to find installed gflags CMake configuration, searching for gflags build directories exported with CMake.
-- Failed to find gflags - Failed to find an installed/exported CMake configuration for gflags, will perform search for installed gflags components.

-- CERES support is disabled. Ceres Solver for reconstruction API is required.
-- Module opencv_ovis disabled because OGRE3D was not found
-- Caffe:   NO
-- Protobuf:   NO

-- Checking for modules 'tesseract;lept'
--   No package 'tesseract' found
--   No package 'lept' found

Finally, the list of modules will be listed after its compilation.

--   OpenCV modules:
--     To be built:                 aruco bgsegm bioinspired calib3d ccalib core cvv datasets dnn dnn_objdetect dpm face features2d flann freetype fuzzy hdf hfs highgui img_hash imgcodecs imgproc java_bindings_generator line_descriptor ml objdetect optflow phase_unwrapping photo plot python_bindings_generator reg rgbd saliency sfm shape stereo stitching structured_light superres surface_matching text tracking ts video videoio videostab xfeatures2d ximgproc xobjdetect xphoto
--     Disabled:                    js world
--     Disabled by dependency:      -
--     Unavailable:                 cnn_3dobj cudaarithm cudabgsegm cudacodec cudafeatures2d cudafilters cudaimgproc cudalegacy cudaobjdetect cudaoptflow cudastereo cudawarping cudev dnn_modern java matlab ovis python2 python3 viz
--     Applications:                tests perf_tests examples apps
--     Documentation:               NO
--     Non-free algorithms:         NO
--
--   GUI:
--     QT:                          YES (ver 5.5.1)
--       QT OpenGL support:         YES (Qt5::OpenGL 5.5.1)
--     GTK+:                        NO
--     OpenGL support:              YES (/usr/lib/x86_64-linux-gnu/libGLU.so /usr/lib/x86_64-linux-gnu/libGL.so)
--     VTK support:                 NO
--
--   Media I/O:
--     ZLib:                        /usr/lib/x86_64-linux-gnu/libz.so (ver 1.2.8)
--     JPEG:                        /usr/lib/x86_64-linux-gnu/libjpeg.so (ver )
--     WEBP:                        build (ver encoder: 0x020e)
--     PNG:                         /usr/lib/x86_64-linux-gnu/libpng.so (ver 1.2.54)
--     TIFF:                        /usr/lib/x86_64-linux-gnu/libtiff.so (ver 42 / 4.0.6)
--     JPEG 2000:                   /usr/lib/x86_64-linux-gnu/libjasper.so (ver 1.900.1)
--     OpenEXR:                     /usr/lib/x86_64-linux-gnu/libImath.so /usr/lib/x86_64-linux-gnu/libIlmImf.so /usr/lib/x86_64-linux-gnu/libIex.so /usr/lib/x86_64-linux-gnu/libHalf.so /usr/lib/x86_64-linux-gnu/libIlmThread.so (ver 2.2.0)
--
--   Video I/O:
--     DC1394:                      YES (ver 2.2.4)
--     FFMPEG:                      YES
--       avcodec:                   YES (ver 56.60.100)
--       avformat:                  YES (ver 56.40.101)
--       avutil:                    YES (ver 54.31.100)
--       swscale:                   YES (ver 3.1.101)
--       avresample:                YES (ver 2.1.0)
--     GStreamer:                   
--       base:                      YES (ver 0.10.36)
--       video:                     YES (ver 0.10.36)
--       app:                       YES (ver 0.10.36)
--       riff:                      YES (ver 0.10.36)
--       pbutils:                   YES (ver 0.10.36)
--     libv4l/libv4l2:              NO
--     v4l/v4l2:                    linux/videodev2.h
--     gPhoto2:                     YES
--
--   Parallel framework:            TBB (ver 4.4 interface 9002)
--
--   Trace:                         YES (with Intel ITT)
--
--   Other third-party libraries:
--     Intel IPP:                   2017.0.3 [2017.0.3]
--            at:                   /home/tanqiwei/Documents/environment/opencv-3.4.1/build/3rdparty/ippicv/ippicv_lnx
--     Intel IPP IW:                sources (2017.0.3)
--               at:                /home/tanqiwei/Documents/environment/opencv-3.4.1/build/3rdparty/ippicv/ippiw_lnx
--     Lapack:                      YES (/usr/lib/liblapack.so /usr/lib/libcblas.so /usr/lib/libatlas.so)
--     Eigen:                       YES (ver 3.2.92)
--     Custom HAL:                  NO
--     Protobuf:                    build (3.5.1)
--
--   NVIDIA CUDA:                   NO
--
--   OpenCL:                        YES (no extra features)
--     Include path:                /home/tanqiwei/Documents/environment/opencv-3.4.1/3rdparty/include/opencl/1.2
--     Link libraries:              Dynamic load
--
--   Python (for build):            /usr/bin/python3
--
--   Java:                          
--     ant:                         NO
--     JNI:                         NO
--     Java wrappers:               NO
--     Java tests:                  NO
--
--   Matlab:                        NO
--
--   Install to:                    /usr/local
-- -----------------------------------------------------------------
--
-- Configuring done
-- Generating done
-- Build files have been written to: /home/tanqiwei/Documents/environment/opencv-3.4.1/build

We may find that we have been successfully compiled, the next step can be carried out, that is make, but it is worth noting that, if an error might make use of multi-core, to be safe, I still make the original command, without -j.

make

Then install.

sudo make install

Finally, the best open restarted once, after I had installed, restart the virtual machine directly to Ben collapse, unable to enter the interior systems, the main reason is not clear, but into some kind of graphics mode, the graphics mode is said to be damaged, then had to back up from a snapshot recover, of course, there was probably installed a small part of the necessary items depend on the possibility of maybe also recommended to install the machine's memory to be bigger, 4GB general, 6GB good, 8GB good.
Run the test

We run examples for testing. You can choose any example, I chose to test in opencv example of my github.

git clone https://github.com/tanqiwei/myOpencvStudyCode.git

About the contents of several M, then into myOpencvStudyCode / LearningOpencv3 / chapter2 / example2.1
followed by the following command

mkdir build
cd build
cmake ..
make
./example2_1 ../data/test.jpg

You can find a successful run, therefore we installed smoothly. Will find the picture window is displayed, press the ESC key to exit.
After the restart, but also found open, the help system installed virtual machine 16.04 of success.

Setup Command Summary

# 安装及下载,该操作不解释,都放在一个统一目录下
# 我的是/home/tanqiwei/Documents/environment
# 也就是在environment文件夹里有opencv-3.4.1和opencv_contrib-3.4.1两个文件夹

# 安装必备库,cmake,git,g++
sudo apt-get install build-essential
sudo apt-get install cmake git g++
# 安装依赖项
sudo apt-get install libgtk2.0-dev pkg-config libavcodec-dev libavformat-dev libswscale-dev libv4l-dev liblapacke-dev
sudo apt-get install checkinstall yasm libxine2-dev libgstreamer0.10-dev libgstreamer-plugins-base0.10-dev libfaac-dev libmp3lame-dev libtheora-dev
sudo apt-get install libopencore-amrnb-dev libopencore-amrwb-dev libavresample-dev x264 v4l-utils
# 处理图像所需的包
sudo apt-get install libtbb2 libtbb-dev libjpeg-dev libpng-dev libtiff-dev libjasper-dev libdc1394-22-dev
# 处理视频所需的包
sudo apt-get install libxvidcore-dev libx264-dev ffmpeg
# opencv功能优化
sudo apt-get install libatlas-base-dev gfortran
# 某些依赖包
sudo apt-get install libopencv-dev  libqt4-dev qt4-qmake libqglviewer-dev libsuitesparse-dev libcxsparse3.1.4 libcholmod3.0.6
sudo apt-get install python-dev python-numpy
# 可选依赖项
sudo apt-get install libprotobuf-dev protobuf-compiler
sudo apt-get install libgoogle-glog-dev libgflags-dev
sudo apt-get install libgphoto2-dev libeigen3-dev libhdf5-dev doxygen

# 进入opencv源码目录,注意opencv和opencv_contrib同级,
# 即都属于同一个主目录下,我的目录为/home/tanqiwei/Documents/environment,
# 下面有opencv-3.4.1和opencv_contrib-3.4.1


mkdir build
cd build
cmake -D CMAKE_BUILD_TYPE=RELEASE -D CMAKE_INSTALL_PREFIX=/usr/local -D INSTALL_C_EXAMPLES=ON -D INSTALL_PYTHON_EXAMPLES=ON -D WITH_TBB=ON -D WITH_V4L=ON -D WITH_QT=ON -D WITH_OPENGL=ON -D OPENCV_EXTRA_MODULES_PATH=../../opencv_contrib-3.4.1/modules -D PYTHON_EXECUTABLE=/usr/bin/python3.5 -D BUILD_EXAMPLES=ON ..
make
sudo make install
 

 

Guess you like

Origin blog.csdn.net/wb790238030/article/details/88428850