1. Install dependencies
sudo apt install build-essential \
sudo apt install libopenexr-dev \
sudo apt install libgtk2.0-dev \
sudo apt install libavcodec-dev \
sudo apt install libavformat-dev \
sudo apt install libjpeg-dev \
sudo apt install libtiff-dev \
sudo apt install libswscale-dev \
sudo apt install libpng-dev \
sudo apt install software-properties-common \
sudo add-apt-repository "deb http://security.ubuntu.com/ubuntu xenial-security main" \
sudo apt update \
sudo apt install libjasper1 libjasper-dev
2. Download opencv-4.5.0 and opencv-contrib-4.5.0
wget https://github.com/opencv/opencv/archive/4.5.0.zip
wget https://github.com/opencv/opencv_contrib/archive/4.5.0.zip
unzip opencv-4.5.0.zip
unzip opencv_contrib-4.5.0.zip
3. Add opencv_contrib dependency file
1) Move opencv_contrib-4.5.0 to the root directory of opencv-4.5.0
mv opencv_contrib-4.5.0 opencv-4.5.0
2) Add the following files in the opencv_contrib-4.5.0/modules/xfeatures2d/src/ directory:
boostdesc_bgm.i
boostdesc_bgm_bi.i
boostdesc_lbgm.i
boostdesc_bgm_hd.i
boostdesc_binboost_064.i
boostdesc_binboost_128.i
boostdesc_binboost_256.i
vgg_generated_120.i
vgg_generated_80.i
vgg_generated_64.i
vgg_generated_48.i
The above file download address is:
https://files.cnblogs.com/files/arxive/boostdesc_bgm.i%2Cvgg_generated_48.i%E7%AD%89.rar
3) Copy the header file
Put the following files in the opencv-4.5.0/modules/features2d/test/ directory:
test_descriptors_invariance.impl.hpp
test_descriptors_regression.impl.hpp
test_detectors_invariance.impl.hpp
test_detectors_regression.impl.hpp
test_invariance_utils.hpp
Copy it to the opencv_contrib-4.5.0/modules/xfeatures2d/test/ directory.
4) Modify the header file
(1) The header file code contained in the opencv_contrib-4.5.0/modules/xfeatures2d/test/test_features2d.cpp file:
#include "features2d/test/test_detectors_regression.impl.hpp"
#include "features2d/test/test_descriptors_regression.impl.hpp"
change into:
#include "test_detectors_regression.impl.hpp"
#include "test_descriptors_regression.impl.hpp"
(2) The header file code contained in the opencv_contrib-4.2.0/modules/xfeatures2d/test/test_rotation_and_scale_invariance.cpp file:
#include "features2d/test/test_detectors_invariance.impl.hpp"
#include "features2d/test/test_descriptors_invariance.impl.hpp"
change into:
#include "test_detectors_invariance.impl.hpp"
#include "test_descriptors_invariance.impl.hpp"
4. Compile opencv
Create a build.sh script in the root directory of opencv-4.5.0. The script content is as follows:
#!/bin/bash
if [[ ! -d build ]]; then
mkdir build
fi
cd build
rm -rf *
cmake -D CMAKE_BUILD_TYPE=RELEASE \
-D CMAKE_INSTALL_PREFIX=install \
-D OPENCV_EXTRA_MODULES_PATH=../opencv_contrib-4.5.0/modules \
-D OPENCV_ENABLE_NONFREE=ON \
..
make -j16
make install
Compile:
chmod +x build.sh
./build.sh
After the compilation is completed, opencv's header files, libraries and other files are installed in the opencv-4.5.0/build/install directory.