Download, configure, install and compile opencv on Ubuntu

1 Install related dependencies

Before installing opencv, you need to prepare the compiler and related dependencies

sudo apt-get install gcc g++ cmake vim
sudo apt-get install build-essential libgtk2.0-dev libavcodec-dev libavformat-dev libjpeg-dev libswscale-dev libtiff5-dev
sudo apt-get install libgtk2.0-dev
sudo apt-get install pkg-config

If sudo is not installed, then

apt-get update
apt-get install sudo

2 downloads

git clone https://gitcode.net/opencv/opencv

3 configuration

cd opencv
mkdir build
cd build

sudo cmake -D CMAKE_BUILD_TYPE=Release -D CMAKE_INSTALL_PREFIX=/usr/local .. -D OPENCV_GENERATE_PKGCONFIG=ON

It should be noted that " -D OPENCV_GENERATE_PKGCONFIG=ON " should be set , otherwise an error will be reported when entering the following command,

pkg-config --cflags opencv

Package opencv was not found in the pkg-config search path.
Perhaps you should add the directory containing `opencv.pc'
to the PKG_CONFIG_PATH environment variable
No package 'opencv' found

4 compile

sudo make -j [number of threads], such as

sudo make -j8

5 installation

sudo make install

6 Environment configuration

  1. Modify /etc/ld.so.conf

sudo vim /etc/ld.so.conf

After opening the file, add at the end

include /usr/local/lib

Enter the following command to update the system shared link library

sudo ldconfig
  1. Modify /etc/bash.bashrc

sudo vim /etc/bash.bashrc

After opening the file, add at the end

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

activate profile

source /etc/bash.bashrc

7 View version

pkg-config opencv4 --modversion

Guess you like

Origin blog.csdn.net/qq_38964360/article/details/129739804