Install OpenCV4 on Ubuntu

Reference: ubuntu environment installation opencv4_ubuntu installation opencv4_jbyyy, blog-CSDN blog

Table of contents

1. Download OpenCV

2. Install dependencies

3. Configure CMake to cross-compile OpenCV

4. Compile OpenCV

5. System configuration, environment variable configuration

5.1. Execute the following command to edit the file (create it if it does not exist):

5.2. Add the following content at the end of the opened opencv.conf file:

5.3. Execute configuration:

5.4. Execute the following command to edit the file (create it if it does not exist):

5.5. Now that the configuration is complete, exit the console, reopen it, and execute the command


1. Download OpenCV

Download address: Releases - OpenCV

Ubuntu select Sources version

2. Install dependencies

OpenCV dependencies

sudo apt-get install build-essential
sudo apt-get install cmake git libgtk2.0-dev pkg-config libavcodec-dev libavformat-dev libswscale-dev
sudo apt-get install python-dev python-numpy libtbb2 libtbb-dev libjpeg-dev libpng-dev libtiff-dev libjasper-dev libdc1394-22-dev
安装gstreamer依赖文件
sudo apt-get -y install libgstreamer0.10-dev libgstreamer-plugins-base0.10-dev libgstreamer1.0-dev
if No package ‘gtk+-3.0‘ found
sudo apt install -y libgtk-3-dev

CMake compilation tool

sudo apt-get install cmake
sudo apt  install cmake-qt-gui
sudo apt-get install libgtk2.0-dev
sudo apt-get install pkg-config

3. Configure CMake to cross-compile OpenCV

Here we mainly refer to ubuntu environment installation opencv4_ubuntu installation opencv4_jbyyy, blog-CSDN blog

After clicking Configure, it may take a while to configure, about 10 minutes.

Configuration completed

world mode

build type

install path

pkg option

Click Configure again and wait about 3 minutes.

Finally click Generate, it will take about 3 minutes.

4. Compile OpenCV

In the build folder, execute the command

make -j4 && make install

This process takes about 10 minutes.

5. System configuration, environment variable configuration

5.1. Execute the following command to edit the file (create it if it does not exist):

sudo gedit /etc/ld.so.conf.d/opencv.conf

5.2. Add the following content at the end of the opened opencv.conf file:

/home/wcx/opencv-4.6.0/build/install/lib

(i.e. the prefix path + /lib just set)

Everyone’s address is different. Don’t just copy and paste it.

5.3. Execute configuration:

sudo ldconfig

5.4. Execute the following command to edit the file (create it if it does not exist):

sudo gedit ~/.bashrc

Add the following content at the end of the opened bash.bashrc file:

PKG_CONFIG_PATH=$PKG_CONFIG_PATH:/home/wcx/opencv-4.6.0/build/install/lib/pkgconfig
export PKG_CONFIG_PATH

(PKG_CONFIG_PATH=$PKG_CONFIG_PATH: the prefix path just set + /lib/pkgconfig)

Effective environment variables

source ~/.bashrc

5.5. Now that the configuration is complete, exit the console, reopen it, and execute the command

pkg-config --modversion opencv4

Successful installation.

Guess you like

Origin blog.csdn.net/qq_45461410/article/details/131751643