Compile with cmake installed OpenCV3 on Ubuntu16.04LTS

First, the source code ready: opencv, cmake

1, opencv official website https://opencv.org/ Download Source Package: opencv-3.4.0.tar.gz

2, cmake official website https://cmake.org/ Download Source Package: cmake-3.10.2.tar.gz

 

Second, install cmake

1, extract the source directory after the files are decompressed

    $ Tar -zxvf cmake-3.10.2.tar.gz

    $ cd cmake-3.10.2

 

2, read README.rst document, follow the instructions:

 

Interpretation: First, have a C ++ compiler, but also to support the C ++ 11 standard (g ++ version is too low to be wrong, please upgrade themselves); then run $ ./bootstrap script configuration, you can use some items, such as "--help "," - prefix "(installation directory); after bootstrap successfully executed $ make $ make install.

In short, it is three commands:

$ ./bootstrap    

$ make    

$ sudo make install

The installation is complete, the next detection: 

$ cmake --version

 

Get, is that simple.

 

PS: It is said that there is a more simple and crude way:

$ sudo apt-get install cmake


Third, the dependent libraries

$ sudo apt-get install build-essential libgtk2.0-dev libavcodec-dev libavformat-dev libjpeg-dev libtiff4-dev libswscale-dev libjasper-dev


Fourth, the installation Opencv

1, extract the source directory after the files are decompressed

    $ tar -zxvf opencv-3.4.0.tar.gz

    $ cd opencv-3.4.0

 

2. Create a folder compiled build, build into the

    $ mkdir build

    $cd build

 

3, the following command, CMAKE_INSTALL_PREFIX = path, "..": CMakeLists.txt path (after decompression in opencv)


    $ cmake -D CMAKE_BUILD_TYPE=Release -D CMAKE_INSTALL_PREFIX=/usr/local ..

 

At this point, there is some accident in the 3.2.0 version, the following error occurs:

-- ICV: Downloading ippicv_linux_20151201.tgz...
CMake Error at 3rdparty/ippicv/downloader.cmake:73 (file):
file DOWNLOAD HASH mismatch

for file: [/root/library/opencv/opencv-3.2.0/3rdparty/ippicv/downloads/linux-808b791a6eac9ed78d32a7666804320e/ippicv_linux_20151201.tgz]
expected hash: [808b791a6eac9ed78d32a7666804320e]
actual hash: [d41d8cd98f00b204e9800998ecf8427e]
status: [1;"Unsupported protocol"]

Call Stack (most recent call first):
3rdparty/ippicv/downloader.cmake:110 (_icv_downloader)
cmake/OpenCVFindIPP.cmake:243 (include)
cmake/OpenCVFindLibsPerf.cmake:37 (include)
CMakeLists.txt:558 (include)


CMake Error at 3rdparty/ippicv/downloader.cmake:77 (message):
ICV: Failed to download ICV package: ippicv_linux_20151201.tgz.
Status=1;"Unsupported protocol"
Call Stack (most recent call first):
3rdparty/ippicv/downloader.cmake:110 (_icv_downloader)
cmake/OpenCVFindIPP.cmake:243 (include)
cmake/OpenCVFindLibsPerf.cmake:37 (include)
CMakeLists.txt:558 (include)


-- Configuring incomplete, errors occurred!
See also "/root/library/opencv/opencv-3.2.0/build/CMakeFiles/CMakeOutput.log".
See also "/root/library/opencv/opencv-3.2.0/build/CMakeFiles/CMakeError.log".


Baidu search the next: in the process of installing opencv to download ippicv_linux_20151201.tgz, due to the network, download this file often fail.

Solution: 

    1. Manually download ippicv_linux_20151201.tgz; can Baidu, a lot.

    2. Create opencv-3.2.0 / 3rdparty / ippicv / downloads / linux-808b791a6eac9ed78d32a7666804320e / directory

   Do not copy! ! ! The error messages output directory selected according to create, as :( deliberately posted the error message so many lines, it is to illustrate this point)


File for: [/root/library/opencv/opencv-3.2.0/3rdparty/ippicv/downloads/linux-808b791a6eac9ed78d32a7666804320e/ippicv_linux_20151201.tgz]
    3. The downloaded files are placed in the directory;

    4. Re-execute cmake command.

 

4, the compiler (Unknown error: Ubuntu1204 error normal 1404; speculation may be dependent on the library version of the problem)

    $ make

 

5, the installation

        $ make install

 

6, opencv configuration environment variable

    $ Vi /etc/ld.so.conf.d/opencv.conf (file or empty, newly created)

    Add: / usr / local / lib

    $ Ldconfig // entry into force

 

7, configuration bash

    $ We /etc/bash.bashrc

    Add the following two lines of text at the end:

    PKG_CONFIG_PATH=$PKG_CONFIG_PATH:/usr/local/lib/pkgconfig

    export PKG_CONFIG_PATH

    $ Source /etc/bash.bashrc // entry into force

 

Five test

Use own test, at samples / cpp / example_cmake


Under interested can read how example_cmake under CMakeLists.txt was written, there are a lot of comments.

    $ cmake .
    $ make

    $ ./opencv_example

 


1, no camera environment:

Built with OpenCV 3.4.0
No capture

 

 

2, a camera environment:

Built with OpenCV 3.4.0
Capture is opened
select timeout
select timeout
OpenCV Error: Assertion failed (total() == 0 || data != __null) in Mat, file /root/library/opencv/opencv-3.4.0/modules/core/include/opencv2/core/mat.inl.hpp, line 500
terminate called after throwing an instance of 'cv::Exception'
  what():  /root/library/opencv/opencv-3.4.0/modules/core/include/opencv2/core/mat.inl.hpp:500: error: (-215) total() == 0 || data != __null in function Mat

Abandoned (core dumped)

 

Run Error: Open the camera timeout! ! !

The reason has not been found, the first aside.

This issue has been resolved, see [Ubuntu virtual machine fails to open the camera and the camera OpenCV open question timeout]! ! !

After the effect of the problem:

---------------------
Author: Zeng brother _zeng
Source: CSDN
Original: https: //blog.csdn.net/qq_30155503/article/details/79419206

Guess you like

Origin www.cnblogs.com/lx17746071609/p/10981127.html