Install opencv-4.3.0 under ubuntu19.10

Opencv is an important software warehouse in computer vision, and many image processing in deep learning are applied to this library. This article mainly introduces how to install opencv under Ubuntu 19.10 system

1. Install cmake

The installation of cmake will not be described too much. For details, please see another blog post of the author: ubuntu19.10 torch7 environment installation tutorial

2. Install Qt5

Qt5 is to be able to support some graphical interface support in Opencv. If not necessary, you can skip this step and proceed to the next step.
The installation of Qt5 can be downloaded and installed directly on the official website : Qt5 official website . There are many installation packages for each version of QT5. Below is a screenshot of my information on the official website:
Qt installation package

The author here chose the latest version of Qt5.14.2 for installation. To install Qt5, you need to register an account information on the official website for registration, download and installation.

3. Install some dependencies of OpenCV

The operation of OpenCV requires some underlying dependent library support. We install the following dependent library files:

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

During the installation process, there may be a problem that the OpenCV dependency package libjasper-dev cannot be installed, so the dependency library file can be installed by the following installation method:

sudo add-apt-repository "deb http://security.ubuntu.com/ubuntu xenial-security main"
sudo apt update
sudo apt install libjasper1 libjasper-dev

4. Download OpenCV and install

We download the OpenCV library from the official website for source installation. The website of the official website is here , and the author chooses to install the latest version of the OpenCV library: OpenCV 4.3.0 The following is a screenshot of the official website:
OpenCV screenshot information

Now start to install and
unzip

unzip opencv-4.3.0.zip

Go into the folder and create a compilation directory

cd opencv-4.3.0
mkdir release && cd release

cmake compilation environment

sudo cmake -D CMAKE_BUILD_TYPE=RELEASE \
-D CMAKE_INSTALL_PREFIX=/usr/local \
-D CMAKE_PREFIX_PATH=/home/asus/Qt5.14.2/5.14.2/gcc_64/lib/cmake/Qt5 \
-D WITH_TBB=ON \
-D WITH_V4L=ON \
-D WITH_QT=ON \
-D WITH_GTK=ON \
-D WITH_OPENGL=ON \
-D WITH_VTK=ON \
-D OPENCV_GENERATE_PKGCONFIG=YES ..

Where CMAKE_PREFIX_PATH is the path where Qt5Config.make is specified. If not specified, the following problems will occur:

    CMake Error at cmake/OpenCVFindLibsGUI.cmake:18 (find_package):
    Could not find a package configuration file provided by "Qt5" with any of
    the following names:

     Qt5Config.cmake
     qt5-config.cmake

    Add the installation prefix of "Qt5" to CMAKE_PREFIX_PATH or set "Qt5_DIR"
    to a directory containing one of the above files. If "Qt5" provides a
    separate development package or SDK, be sure it has been installed.

Where CMAKE_INSTALL_PREFIX is the path environment of the specified installation. If you don't need opencv to support the Qt user interface, you can delete the two lines -D WITH_QT=ON \ and -D CMAKE_PREFIX_PATH=/opt/Qt5.13.0/5.13.0/gcc_64/lib/cmake/Qt5 \
make, compile and install

make -j$(nproc)  #其中nproc是读取CPU核心的数量
sudo make install 

In this way, OpenCV is successfully installed, and we need to configure the environment of OpenCV:
add environment variables and update the system library

sudo nano /etc/ld.so.conf.d/opencv.conf
# 打开之后可能是空文件,在文件内容的最后添加
/usr/local/lib
sudo ldconfig

Configure bash

sudo nano /etc/bash.bashrc
#在文件的末尾添加以下内容
export PKG_CONFIG_PATH=$PKG_CONFIG_PATH:/usr/local/lib/pkgconfig 
#使得环境生效
sudo -s
source /etc/profile

This will finally complete the environment installation

5. Uninstallation of OpenCV environment

Here we also introduce the uninstall method of the following OpenCV environment, which needs to enter the previous installation environment folder (here is release) and execute the following command:

sudo make uninstall
cd ..
sudo rm -r release
sudo rm -r /usr/local/include/opencv2 /usr/local/include/opencv /usr/include/opencv /usr/include/opencv2 /usr/local/share/opencv /usr/local/share/OpenCV /usr/share/opencv /usr/share/OpenCV /usr/local/bin/opencv* /usr/local/lib/libopencv*

At this step, there may be an error to
perform the following operations:

sudo apt-get –purge remove opencv-doc opencv-data python-opencv

In this way, the OpencvCV environment can be uninstalled.

Guess you like

Origin blog.csdn.net/Zhang_Pro/article/details/105902247