Ubuntu 编译opencv-4.5.0与opencv-contrib-4.5.0

1. 安装依赖

sudo apt install build-essential \
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 add-apt-repository "deb http://security.ubuntu.com/ubuntu xenial-security main" \
sudo apt update \
sudo apt install libjasper1 libjasper-dev

2. 下载opencv-4.5.0与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. 添加opencv_contrib依赖文件

1)移动opencv_contrib-4.5.0到opencv-4.5.0根目录下

mv opencv_contrib-4.5.0 opencv-4.5.0

2)在opencv_contrib-4.5.0/modules/xfeatures2d/src/目录下添加如下文件:

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

上述文件下载地址为:

https://files.cnblogs.com/files/arxive/boostdesc_bgm.i%2Cvgg_generated_48.i%E7%AD%89.rar

3)拷贝头文件

将opencv-4.5.0/modules/features2d/test/目录下的如下文件:

test_descriptors_invariance.impl.hpp
test_descriptors_regression.impl.hpp
test_detectors_invariance.impl.hpp
test_detectors_regression.impl.hpp
test_invariance_utils.hpp

拷至opencv_contrib-4.5.0/modules/xfeatures2d/test/目录下。

4)修改头文件

(1)将opencv_contrib-4.5.0/modules/xfeatures2d/test/test_features2d.cpp文件中包含的头文件代码:

#include "features2d/test/test_detectors_regression.impl.hpp"
#include "features2d/test/test_descriptors_regression.impl.hpp"

修改为:

#include "test_detectors_regression.impl.hpp"
#include "test_descriptors_regression.impl.hpp"

(2)将opencv_contrib-4.2.0/modules/xfeatures2d/test/test_rotation_and_scale_invariance.cpp文件中包含的头文件代码:

#include "features2d/test/test_detectors_invariance.impl.hpp" 
#include "features2d/test/test_descriptors_invariance.impl.hpp"

修改为:

#include "test_detectors_invariance.impl.hpp"
#include "test_descriptors_invariance.impl.hpp"

4. 编译opencv

在opencv-4.5.0根目录下创建build.sh的脚本,脚本内容如下:

#!/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

编译:

chmod +x build.sh
./build.sh

编译完成后,opencv的头文件、库等文件安装到opencv-4.5.0/build/install目录下。

你可能感兴趣的:(opencv,opencv,ubuntu,人工智能)