ubuntu20.04 install opencv steps and dependency error: E: Unable to locate the package libjasper-dev

The first step: dependency detection

sudo apt install build-essential
sudo apt install cmake git libgtk2.0-dev pkg-config libavcodec-dev libavformat-dev libswscale-dev
sudo apt install python-dev python-numpy libtbb2 libtbb-dev libjpeg-dev libpng-dev libtiff-dev libjasper-dev libdc1394-22-dev

Before installing opencv, directly execute the above three commands to complete dependency detection, which is equivalent to a fool-style one-click installation. Look carefully at these three commands, it installs all the libraries that opencv needs to depend on. If an error occurs, go to the end to view the solution.

Step 2: Download the source code.
After we execute the above three commands, it means that all the dependencies for installing opencv are met. Let's download the source code first.

Download source code

git clone https://github.com/opencv/opencv.git
git clone https://github.com/opencv/opencv_contrib.git

Download the source code to the folder you want, and move the opencv_contrib library to the opencv folder

Note that there are two opencv, one is the core library, the other is the contribution library, there are some newest functions in the contribution library. It is best to install both during the first installation, and don't come back and reinstall at that time. The opencv_contrib library is also useful.

Step 3: Compile
Why compile? Can't it be used directly? Of course not. What we downloaded is only the source code, which is a bunch of .h .cpp files. You must compile them into .a files (static libraries) or .so files (dynamic libraries) before others can use them. So start compiling.

First create a build folder to store .so files

cd ~/opencv
mkdir build
cd build

Start compiling

cmake -D CMAKE_BUILD_TYPE=Release -D CMAKE_INSTALL_PREFIX=/usr/local -D OPENCV_EXTRA_MODULES_PATH=../opencv_contrib/modules -D DOPENCV_GENERATE_PKGCONFIG=ON ..

This command is the most important, and it is worth taking 10 minutes to take a closer look. -CMAKE_BUILD_TYPE=Release represents whether you want to edit the release version or the debug version. CMAKE_INSTALL_PREFIX is where your .so file is finally placed (check the /usr/local/lib file after installation, there must be opencv library files). There are other options, such as OPENCV_EXTRA_MODULES_PATH = …/opencv_contrib/modules, which means compiling and contributing libraries at the same time. -DOPENCV_GENERATE_PKGCONFIG=ON is used to generate .pc files, this option must be added.

Install the compiled library, perhaps to install the library to the system directory

sudo make install
sudo ldconfig

Step 4: Verification

pkg-config --modversion opencv

The above series of commands can be executed with your eyes closed. They are all linear. Just pay attention to the bold letters. If there is an error in the middle step, Baidu can do it. Generally, the problem is not big. Record the installation steps in detail so that you can quickly deploy after changing the environment.

Error: E: Unable to locate the package libjasper-dev

solution:

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

Successfully solved the problem, among which libjasper1 is a dependency package of libjasper-dev

Guess you like

Origin blog.csdn.net/BigData_Mining/article/details/111826692