ubuntu20.04 download opencv4.5.2

Recently, I accidentally formatted my computer for some reason (don’t say anything, it’s just a capitalized miserable, woo woo woo, and there is no backup file yet) so here is a reminder to everyone, the file must be backed up! must! must! Must. After reinstalling the system, now download back various software, one of which is to download OpenCV in the Ubuntu system. The other versions are pretty much the same!

Table of Contents

  • 1. Download the installation package
  • 2. Start downloading
  • 3. Start configuration
  • Fourth, verify whether the installation is successful

1. Download the installation package

1. Go to the official website to download the OpenCV installation package, remember to [Sources], here is a direct link:

https://opencv.org/releases/

2. Go to the location where the installation package was downloaded, right-click on the blank space, select [Open in Terminal], and enter the terminal

2. Start download

1. Enter the following code to decompress the installation package
Here if you think the name of the installation package is too long and you don’t want to lose it, you can enter it in the [op] of [opencv]
Click the [TAB] key, the system will automatically add

unzip opencv-4.5.2.zip


2. After completion, enter and download cmake

sudo apt-get install cmake


This kind of problem is often encountered when downloading files. Generally, as long as you actively want to download, you can enter [Y], which can be uppercase or lowercase.

3. Continue to enter the following code to install the libraries that opencv depends on

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

You may encounter this problem here, if you don’t encounter it, you can skip it directly

This is the solution found
Enter in turn, that’s it

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

Then enter the following code to continue installing dependent libraries

sudo apt-get install build-essential cmake unzip pkg-config
sudo apt-get install libxvidcore-dev libx264-dev
sudo apt-get install libgtk-3-dev
sudo apt-get install libatlas-base-dev gfortran
sudo apt-get install python3-dev

3. Start configuration

1. Rename the decompressed folder mv opencv-4.5.2 opencv to facilitate subsequent operations
enter code
Here is to create a new file named build to store the compiled files

mkdir build
cd build


2. Compile with cmake

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


3. Enter the code again, it may take a long time here

sudo make install

4. Add the .conf file for the library in /etc/ld.so.conf.d/, first create opencv.conf

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

Enter after opening the file (it may be an empty file, it doesn’t matter)

/usr/local/lib

5. Enter the following code to read the data in /etc/ld.so.conf.d into the cache

sudo ldconfig

6. Add the pkg-config environment variable, enter the path after opening the file

sudo gedit /etc/bash.bashrc

Add this path at the end of the file

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

7. Activate after saving and exiting:

source /etc/bash.bashrc

4. Verify that the installation is successful

1. Open the downloaded file, mine is [opencv], enter

2. Find [samples] and enter

3. Find [cpp] and open it

4. Find [example_cmake] and enter

This is the case in my folder, right click in the blank space and enter the terminal

5. In the last step, enter in sequence

cmake .
make
./opencv_example

If your computer camera is automatically turned on, congratulations, the installation is successful! ! !