Install opencv_contrib-3.2.0 closed pit record in ubuntu18.04

Due to the recent use of SIFT and SURF feature extraction in OpenCV3, since OpenCV2 was upgraded to OpenCV3, these algorithms such as SIFT and SURF have been moved out of the opencv default project library and placed in the project library called opencv_contrib. Therefore, you need to manually download the source code of opencv and opencv_contrib, and then put the two source codes together to manually compile and install.

Since my computer is ubuntu18.04 running on a VMware virtual machine, and ROS-melodic is installed in ubuntu18.04, and the opencv-3.2.0 version is installed by default after ROS-melodic is installed. Therefore, in order to be consistent with the opencv-3.2.0 version that comes with ROS-melodic, I downloaded the source code of opencv-3.2.0 and opencv_contrib-3.2.0, manually compiled and installed, to cover the built-in ROS-melodic The opencv-3.2.0 version. Below I have listed my environment:

  • VMware virtual machine
  • free18.04
  • opencv-3.2.0
  • opencv_contrib-3.2.0

1. Download opencv-3.2.0 and opencv_contrib-3.2.0 source code

Just go to github to download, the download address is as follows:

After downloading, unzip these two files to the same folder at the same time. I unzip it in a folder such as opencv_install, as shown in the figure below.

2. Install related dependencies

Before compiling and installing the opencv source code, you need to install the relevant dependency library first. The installation command is as follows:

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

An error will be reported when the above command is executed. The error says that libjaster-dev cannot be installed. The solution is as follows:

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

3. Configure opencv compilation parameters with cmake-gui tool

(1) Install the cmake-gui tool

Before officially compiling the opencv source code, you need to set the CMake parameters in opencv. It is recommended to use the cmake-gui tool to configure. First install the cmake-gui tool, the following command:

sudo apt-get install cmake-gui

(2) Set cmake parameters

Open the terminal and enter the following command to start the cmake-gui tool:

cmake-gui

In the opened interface, set the path of opencv-3.2.0 in the column of where is the source code, and the path of opencv-3.2.0/build in the column of where to build the binaries, as shown in the figure below.

Then click the Configure button to configure. An error will be reported during the configuration process. The error says that there is a lack of vgg_generated_48.i. The solution is to directly download the file vgg_generated_48.i from the Internet. The download address is as follows:

https://download.csdn.net/download/u013085286/10309843

After downloading vgg_generated_48.i, copy this file to the path indicated in the error report. Take my path as an example, copy it with the following command:

cp vgg_generated_48.i /home/ubuntu1804/Downloads/opencv_install/opencv_contrib-3.2.0/modules/xfeatures2d/cmake/.download/e8d0dcd54d1bcfdc29203d011a797179/vgg_generated_48.i

The e8d0dcd54d1bcfdc29203d011a797179 in the path in the above command shall prevail according to your actual error message. For similar errors of missing these files, go to the Internet to download the corresponding files, and solve them in the same way. After completing these files, click Configure again

(3) Set cmake compilation parameters

Set the values ​​of the following parameters in the interface. The specific parameters and values ​​are as follows: The value of the CMAKE_BUILD_TYPE parameter is Release, as shown in the figure below.

 The value of the OPENCV_EXTRA_MODULES_PATH parameter is /home/ubuntu1804/Downloads/opencv_contrib-3.2.0/modules, and the first few folders of this path are replaced with your actual path, as shown in the figure below.

 The CMAKE_INSTALL_PREFIX parameter takes the value /usr/local, as shown in the figure below.

 It needs to be mentioned here that the value of the ENABLE_PRECOMPILED_HEADERS parameter needs to be set to OFF. If this parameter is not turned off, an error will be reported later when compiling /usr/include/c++/7/cstdlib:75:15:fatal error:stdlib.h:No such file or direct.

 

After the above compilation parameters are set, you can click the Generate button to generate the makefile.

4. Compile and install opencv

Switch to the opencv-3.2.0/build directory, compile and install with make and make install.

cd ~/Downloads/opencv_install/opencv-3.2.0/build/ 
make 
sudo make install

When you execute the above command and see 100%, congratulations! Successful installation!

references

[1] Zhang Hu, Robot SLAM Navigation Core Technology and Practice [M]. Machinery Industry Press, 2022.

Guess you like

Origin blog.csdn.net/m0_68732180/article/details/130253703