如何在 Debian 上为 ARM 交叉编译 OpenCV,并为 gnueabihf 安装依赖项?

如何解决如何在 Debian 上为 ARM 交叉编译 OpenCV,并为 gnueabihf 安装依赖项?

我想达到什么目的?

我正在尝试按照以下 2 个指南为 ARM(用于 Raspberry Pi 4 - Raspberry OS 桌面)交叉编译 OpenCV 4.5.2:

  1. Cross compilation for ARM based Linux systems
  2. Cross compiling OpenCV 4 for Raspberry Pi and BeagleBone Black

我正在经历什么?

但是我可以看到很多关于由于某些 pkg-config 问题而无法找到某些库的 cmake 升温:

#19 39.61 -- Looking for dlerror in dl - found
#19 39.65 -- ADE: Download: v0.1.1f.zip
#19 40.28 -- OpenCV Python: during development append to PYTHONPATH: /opencv-4.5.2/platforms/linux/build/python_loader
#19 40.29 -- Found PkgConfig: /usr/bin/pkg-config (found version "0.29") 
#19 40.30 -- Checking for modules 'libavcodec;libavformat;libavutil;libswscale'
#19 40.33 --   Found libavcodec,version 58.35.100
#19 40.34 --   Found libavformat,version 58.20.100
#19 40.36 --   Found libavutil,version 56.22.100
#19 40.38 --   Found libswscale,version 5.3.100
#19 40.43 CMake Warning at cmake/OpenCVUtils.cmake:882 (message):
#19 40.43   ocv_check_modules(FFMPEG): can't find library 'avcodec'.  Specify
#19 40.43   'pkgcfg_lib_FFMPEG_avcodec' manually
#19 40.43 Call Stack (most recent call first):
#19 40.43   modules/videoio/cmake/detect_ffmpeg.cmake:30 (ocv_check_modules)
#19 40.43   modules/videoio/cmake/init.cmake:7 (include)
#19 40.43   modules/videoio/cmake/init.cmake:18 (add_backend)
#19 40.43   cmake/OpenCVModule.cmake:298 (include)
#19 40.43   cmake/OpenCVModule.cmake:361 (_add_modules_1)
#19 40.43   modules/CMakeLists.txt:7 (ocv_glob_modules)
#19 40.43 
#19 40.43 
#19 40.43 CMake Warning at cmake/OpenCVUtils.cmake:882 (message):
#19 40.43   ocv_check_modules(FFMPEG): can't find library 'avformat'.  Specify
#19 40.43   'pkgcfg_lib_FFMPEG_avformat' manually
#19 40.43 Call Stack (most recent call first):
#19 40.43   modules/videoio/cmake/detect_ffmpeg.cmake:30 (ocv_check_modules)
#19 40.43   modules/videoio/cmake/init.cmake:7 (include)
#19 40.43   modules/videoio/cmake/init.cmake:18 (add_backend)
#19 40.43   cmake/OpenCVModule.cmake:298 (include)
#19 40.43   cmake/OpenCVModule.cmake:361 (_add_modules_1)
#19 40.43   modules/CMakeLists.txt:7 (ocv_glob_modules)

基本上,我看到我自己安装的所有库/依赖项都有类似的警告。

我在做什么?

我在基于 debian:buster(最新)amd64 的 docker 容器中运行编译。

而我所做的是:

  1. 安装开发环境
GNU_HOST=arm-linux-gnueabihf
apt-get update
apt-get upgrade -y
apt-get install -y autoconf \
    automake \
    build-essential \
    ca-certificates \
    curl \
    gcc-$GNU_HOST \
    g++-$GNU_HOST \
    git \
    gnupg \
    jq \
    libssl-dev \
    libtool \
    meson \
    ninja-build \
    openssh-client \
    pipenv \
    pkg-config \
    python-dev \
    python-pip \
    python3-dev \
    python3-pip \
    unzip \
    wget
  1. 启用 armhf arch 并为其安装 OpenCV deps:
apt-get update
apt-get -y upgrade
dpkg --add-architecture armhf
apt-get update
apt-get install -y gfortran-arm-linux-gnueabihf \
    gstreamer1.0-plugins-bad:armhf \
    gstreamer1.0-plugins-good:armhf \
    libatlas-base-dev:armhf \
    libavcodec-dev:armhf \
    libavformat-dev:armhf \
    libdc1394-22-dev:armhf \
    libgstreamer1.0-dev:armhf \
    libgstreamer-plugins-base1.0-dev:armhf \
    libgtk-3-dev:armhf \
    libjpeg-dev:armhf \
    libpng-dev:armhf \
    libpython2-dev:armhf \
    libpython3-dev:armhf \
    libswscale-dev:armhf \
    libtbb-dev:armhf \
    libtbb2:armhf \
    libtiff-dev:armhf \
    libv4l-dev:armhf \
    libxvidcore-dev:armhf \
    libx264-dev:armhf \
    openexr:armhf \
    python-numpy \
    python3-numpy
  1. 设置 pkg-config libdir
HOST_LIBS=/usr/lib

export PKG_CONFIG_PATH=
export PKG_CONFIG_LIBDIR=$HOST_LIBS/$GNU_HOST/pkgconfig
  1. 下载 OpenCV
OPENCV_VERSION=4.5.2
OPENCV_DIR=opencv-$OPENCV_VERSION

wget -O opencv.zip \
  --progress=bar:force:noscroll \
  https://github.com/opencv/opencv/archive/$OPENCV_VERSION.zip
unzip -q opencv.zip
wget -O opencv_contrib.zip \
  --progress=bar:force:noscroll \
  https://github.com/opencv/opencv_contrib/archive/$OPENCV_VERSION.zip
unzip -q opencv_contrib.zip
  1. 配置、构建和安装 OpenCV
CROSS_STAGING_PREFIX=/usr/$GNU_HOST/stage

pushd $OPENCV_DIR

OPENCV_BUILD_DIR=platforms/linux/build
mkdir -p $OPENCV_BUILD_DIR
pushd $OPENCV_BUILD_DIR

cmake -Wno-dev -Wno-deprecated \
  -G "Ninja" \
  -DCMAKE_TOOLCHAIN_FILE=../arm-gnueabi.toolchain.cmake \
  -DCMAKE_INSTALL_PREFIX=$CROSS_STAGING_PREFIX \
  -DCMAKE_BUILD_TYPE=Release \
  -DOPENCV_EXTRA_MODULES_PATH=../../../../opencv_contrib-$OPENCV_VERSION/modules \
  -DOPENCV_ENABLE_NONFREE=ON \
  -DBUILD_PROTOBUF=OFF \
  -DPROTOBUF_UPDATE_FILES=ON \
  ../../..
ninja -j3
ninja install

我需要什么帮助?

此时,我已经尝试了我能想到的所有方法,但我似乎无法找到一种方法来消除这些警告并确保 OpenCV 使用我在编译时安装的库。

基本上,我尝试设置 CMAKE_FIND_ROOT_PATH(类似于 /usr/arm-linux-gnueabihf),但这没有帮助,因为当我使用 apt-get install mylib:armhf 时,libs/headers 并没有在那里结束,但是在/usr/lib/arm-linux-gnueabihf

然后我尝试将 PKG_CONFIG_SYSROOT_DIR 设置为相同的值,但也没有任何运气。

似乎唯一可行的是手动设置每个库,例如:

-DHAVE_JPEG=ON \
-DJPEG_LIBRARY=$HOST_LIBS/$GNU_HOST/libjpeg.so \
-DJPEG_INCLUDE_DIR=$HOST_INCLUDES \

但是我需要为每个库都这样做。

所以我的问题是:有什么方法可以让 cmake 或 pkg-config 在多架构/交叉编译环境中工作吗?

其他信息

我最后得到的 cmake 配置是:

#19 57.95 -- Performing Test HAVE_CXX_WNO_UNUSED_PRIVATE_FIELD - Failed
#19 58.04 -- 
#19 58.04 -- General configuration for OpenCV 4.5.2 =====================================
#19 58.04 --   Version control:               unknown
#19 58.04 -- 
#19 58.05 --   Extra modules:
#19 58.06 --     Location (extra):            /opencv_contrib-4.5.2/modules
#19 58.06 --     Version control (extra):     unknown
#19 58.06 -- 
#19 58.06 --   Platform:
#19 58.06 --     Timestamp:                   2021-05-13T07:07:53Z
#19 58.07 --     Host:                        Linux 5.10.25-linuxkit x86_64
#19 58.07 --     Target:                      Linux 1 arm
#19 58.07 --     CMake:                       3.20.2
#19 58.07 --     CMake generator:             Unix Makefiles
#19 58.07 --     CMake build tool:            /usr/bin/make
#19 58.07 --     Configuration:               Release
#19 58.07 -- 
#19 58.07 --   CPU/HW features:
#19 58.07 --     Baseline:
#19 58.07 --       requested:                 DETECT
#19 58.07 --       disabled:                  VFPV3 NEON
#19 58.07 -- 
#19 58.07 --   C/C++:
#19 58.07 --     Built as dynamic libs?:      YES
#19 58.07 --     C++ standard:                11
#19 58.07 --     C++ Compiler:                /usr/bin/arm-linux-gnueabihf-g++  (ver 8.3.0)
#19 58.07 --     C++ flags (Release):         -mthumb  -fdata-sections -Wa,--noexecstack -fsigned-char -Wno-psabi   -fsigned-char -W -Wall -Werror=return-type -Werror=non-virtual-dtor -Werror=address -Werror=sequence-point -Wformat -Werror=format-security -Wmissing-declarations -Wundef -Winit-self -Wpointer-arith -Wshadow -Wsign-promo -Wuninitialized -Wsuggest-override -Wno-delete-non-virtual-dtor -Wno-comment -Wimplicit-fallthrough=3 -Wno-strict-overflow -fdiagnostics-show-option -pthread -fomit-frame-pointer -ffunction-sections -fdata-sections  -fvisibility=hidden -fvisibility-inlines-hidden -O3 -DNDEBUG  -DNDEBUG
#19 58.07 --     C++ flags (Debug):           -mthumb  -fdata-sections -Wa,--noexecstack -fsigned-char -Wno-psabi   -fsigned-char -W -Wall -Werror=return-type -Werror=non-virtual-dtor -Werror=address -Werror=sequence-point -Wformat -Werror=format-security -Wmissing-declarations -Wundef -Winit-self -Wpointer-arith -Wshadow -Wsign-promo -Wuninitialized -Wsuggest-override -Wno-delete-non-virtual-dtor -Wno-comment -Wimplicit-fallthrough=3 -Wno-strict-overflow -fdiagnostics-show-option -pthread -fomit-frame-pointer -ffunction-sections -fdata-sections  -fvisibility=hidden -fvisibility-inlines-hidden -g  -O0 -DDEBUG -D_DEBUG
#19 58.07 --     C Compiler:                  /usr/bin/arm-linux-gnueabihf-gcc
#19 58.07 --     C flags (Release):           -mthumb  -fdata-sections -Wa,--noexecstack -fsigned-char -Wno-psabi   -fsigned-char -W -Wall -Werror=return-type -Werror=non-virtual-dtor -Werror=address -Werror=sequence-point -Wformat -Werror=format-security -Wmissing-declarations -Wmissing-prototypes -Wstrict-prototypes -Wundef -Winit-self -Wpointer-arith -Wshadow -Wuninitialized -Wno-comment -Wimplicit-fallthrough=3 -Wno-strict-overflow -fdiagnostics-show-option -pthread -fomit-frame-pointer -ffunction-sections -fdata-sections  -fvisibility=hidden -O3 -DNDEBUG  -DNDEBUG
#19 58.07 --     C flags (Debug):             -mthumb  -fdata-sections -Wa,--noexecstack -fsigned-char -Wno-psabi   -fsigned-char -W -Wall -Werror=return-type -Werror=non-virtual-dtor -Werror=address -Werror=sequence-point -Wformat -Werror=format-security -Wmissing-declarations -Wmissing-prototypes -Wstrict-prototypes -Wundef -Winit-self -Wpointer-arith -Wshadow -Wuninitialized -Wno-comment -Wimplicit-fallthrough=3 -Wno-strict-overflow -fdiagnostics-show-option -pthread -fomit-frame-pointer -ffunction-sections -fdata-sections  -fvisibility=hidden -g  -O0 -DDEBUG -D_DEBUG
#19 58.07 --     Linker flags (Release):      -Wl,--fix-cortex-a8 -Wl,--no-undefined -Wl,--gc-sections -Wl,-z,noexecstack -Wl,relro -Wl,now   -Wl,--as-needed  
#19 58.07 --     Linker flags (Debug):        -Wl,--as-needed  
#19 58.07 --     ccache:                      NO
#19 58.07 --     Precompiled headers:         NO
#19 58.09 --     Extra dependencies:          dl m pthread rt
#19 58.09 --     3rdparty dependencies:
#19 58.09 -- 
#19 58.09 --   OpenCV modules:
#19 58.10 --     To be built:                 aruco bgsegm bioinspired calib3d ccalib core datasets dnn dnn_objdetect dnn_superres dpm face features2d flann freetype fuzzy gapi hfs highgui img_hash imgcodecs imgproc intensity_transform line_descriptor mcc ml objdetect optflow phase_unwrapping photo plot python2 python3 quality rapid reg rgbd saliency shape stereo stitching structured_light superres surface_matching text tracking ts video videoio videostab wechat_qrcode xfeatures2d ximgproc xobjdetect xphoto
#19 58.10 --     Disabled:                    world
#19 58.10 --     Disabled by dependency:      -
#19 58.10 --     Unavailable:                 alphamat cnn_3dobj cudaarithm cudabgsegm cudacodec cudafeatures2d cudafilters cudaimgproc cudalegacy cudaobjdetect cudaoptflow cudastereo cudawarping cudev cvv hdf java julia matlab ovis sfm viz
#19 58.10 --     Applications:                tests perf_tests apps
#19 58.10 --     Documentation:               NO
#19 58.10 --     Non-free algorithms:         YES
#19 58.10 -- 
#19 58.10 --   GUI: 
#19 58.10 --     GTK+:                        YES (ver 3.24.5)
#19 58.10 --       GThread :                  YES (ver 2.58.3)
#19 58.10 --       GtkGlExt:                  NO
#19 58.10 -- 
#19 58.10 --   Media I/O: 
#19 58.10 --     ZLib:                        /usr/arm-linux-gnueabihf/stage/lib/libz.so (ver 1.2.11)
#19 58.10 --     JPEG:                        libjpeg-turbo (ver 2.0.6-62)
#19 58.10 --     WEBP:                        build (ver encoder: 0x020f)
#19 58.11 --     PNG:                         build (ver 1.6.37)
#19 58.11 --     TIFF:                        build (ver 42 - 4.2.0)
#19 58.11 --     JPEG 2000:                   build (ver 2.4.0)
#19 58.11 --     HDR:                         YES
#19 58.11 --     SUNRASTER:                   YES
#19 58.11 --     PXM:                         YES
#19 58.11 --     PFM:                         YES
#19 58.11 -- 
#19 58.11 --   Video I/O:
#19 58.11 --     DC1394:                      YES (2.2.5)
#19 58.11 --     FFMPEG:                      YES
#19 58.11 --       avcodec:                   YES (58.35.100)
#19 58.11 --       avformat:                  YES (58.20.100)
#19 58.11 --       avutil:                    YES (56.22.100)
#19 58.11 --       swscale:                   YES (5.3.100)
#19 58.11 --       avresample:                NO
#19 58.11 --     GStreamer:                   YES (1.14.4)
#19 58.11 --     v4l/v4l2:                    YES (linux/videodev2.h)
#19 58.11 -- 
#19 58.11 --   Parallel framework:            pthreads
#19 58.11 -- 
#19 58.11 --   Trace:                         YES (with Intel ITT)
#19 58.11 -- 
#19 58.11 --   Other third-party libraries:
#19 58.11 --     Lapack:                      NO
#19 58.11 --     Custom HAL:                  NO
#19 58.11 --     Protobuf:                    /usr/arm-linux-gnueabihf/stage/lib/libprotobuf.a (3.15.2)
#19 58.12 -- 
#19 58.12 --   OpenCL:                        YES (no extra features)
#19 58.12 --     Include path:                /opencv-4.5.2/3rdparty/include/opencl/1.2
#19 58.12 --     Link libraries:              Dynamic load
#19 58.12 -- 
#19 58.12 --   Python 2:
#19 58.12 --     Interpreter:                 /usr/bin/python2.7 (ver 2.7.16)
#19 58.12 --     Libraries:                   /usr/lib/arm-linux-gnueabihf/libpython2.7.so
#19 58.12 --     numpy:                       /usr/lib/python2/dist-packages/numpy/core/include (ver undefined - cannot be probed because of the cross-compilation)
#19 58.12 --     install path:                lib/python2.7/dist-packages/cv2/python-2.7
#19 58.12 -- 
#19 58.12 --   Python 3:
#19 58.12 --     Interpreter:                 /usr/bin/python3 (ver 3.7.3)
#19 58.12 --     Libraries:                   /usr/lib/arm-linux-gnueabihf/libpython3.7m.so
#19 58.12 --     numpy:                       /usr/lib/python3/dist-packages/numpy/core/include (ver undefined - cannot be probed because of the cross-compilation)
#19 58.12 --     install path:                lib/python3.7/dist-packages/cv2/python-3.7
#19 58.12 -- 
#19 58.12 --   Python (for build):            /usr/bin/python2.7
#19 58.12 -- 
#19 58.12 --   Install to:                    /usr/arm-linux-gnueabihf/stage
#19 58.12 -- -----------------------------------------------------------------
#19 58.12 -- 
#19 58.84 -- Configuring done
#19 59.97 -- Generating done
#19 60.02 -- Build files have been written to: /opencv-4.5.2/platforms/linux/build

所以它以某种方式找到了视频 I/O 库,即使 cmake 对这些库发出了很多警告。但是,它没有找到媒体 I/O 库(PNG、JPEG 等)和 GTK 库,即使我也安装了这些库。

您也可以在 GitHub 上找到更多上下文opencv/opencv#20076

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐


使用本地python环境可以成功执行 import pandas as pd import matplotlib.pyplot as plt # 设置字体 plt.rcParams['font.sans-serif'] = ['SimHei'] # 能正确显示负号 p
错误1:Request method ‘DELETE‘ not supported 错误还原:controller层有一个接口,访问该接口时报错:Request method ‘DELETE‘ not supported 错误原因:没有接收到前端传入的参数,修改为如下 参考 错误2:cannot r
错误1:启动docker镜像时报错:Error response from daemon: driver failed programming external connectivity on endpoint quirky_allen 解决方法:重启docker -> systemctl r
错误1:private field ‘xxx‘ is never assigned 按Altʾnter快捷键,选择第2项 参考:https://blog.csdn.net/shi_hong_fei_hei/article/details/88814070 错误2:启动时报错,不能找到主启动类 #
报错如下,通过源不能下载,最后警告pip需升级版本 Requirement already satisfied: pip in c:\users\ychen\appdata\local\programs\python\python310\lib\site-packages (22.0.4) Coll
错误1:maven打包报错 错误还原:使用maven打包项目时报错如下 [ERROR] Failed to execute goal org.apache.maven.plugins:maven-resources-plugin:3.2.0:resources (default-resources)
错误1:服务调用时报错 服务消费者模块assess通过openFeign调用服务提供者模块hires 如下为服务提供者模块hires的控制层接口 @RestController @RequestMapping("/hires") public class FeignControl
错误1:运行项目后报如下错误 解决方案 报错2:Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.8.1:compile (default-compile) on project sb 解决方案:在pom.
参考 错误原因 过滤器或拦截器在生效时,redisTemplate还没有注入 解决方案:在注入容器时就生效 @Component //项目运行时就注入Spring容器 public class RedisBean { @Resource private RedisTemplate<String
使用vite构建项目报错 C:\Users\ychen\work>npm init @vitejs/app @vitejs/create-app is deprecated, use npm init vite instead C:\Users\ychen\AppData\Local\npm-
参考1 参考2 解决方案 # 点击安装源 协议选择 http:// 路径填写 mirrors.aliyun.com/centos/8.3.2011/BaseOS/x86_64/os URL类型 软件库URL 其他路径 # 版本 7 mirrors.aliyun.com/centos/7/os/x86
报错1 [root@slave1 data_mocker]# kafka-console-consumer.sh --bootstrap-server slave1:9092 --topic topic_db [2023-12-19 18:31:12,770] WARN [Consumer clie
错误1 # 重写数据 hive (edu)> insert overwrite table dwd_trade_cart_add_inc > select data.id, > data.user_id, > data.course_id, > date_format(
错误1 hive (edu)> insert into huanhuan values(1,'haoge'); Query ID = root_20240110071417_fe1517ad-3607-41f4-bdcf-d00b98ac443e Total jobs = 1
报错1:执行到如下就不执行了,没有显示Successfully registered new MBean. [root@slave1 bin]# /usr/local/software/flume-1.9.0/bin/flume-ng agent -n a1 -c /usr/local/softwa
虚拟及没有启动任何服务器查看jps会显示jps,如果没有显示任何东西 [root@slave2 ~]# jps 9647 Jps 解决方案 # 进入/tmp查看 [root@slave1 dfs]# cd /tmp [root@slave1 tmp]# ll 总用量 48 drwxr-xr-x. 2
报错1 hive> show databases; OK Failed with exception java.io.IOException:java.lang.RuntimeException: Error in configuring object Time taken: 0.474 se
报错1 [root@localhost ~]# vim -bash: vim: 未找到命令 安装vim yum -y install vim* # 查看是否安装成功 [root@hadoop01 hadoop]# rpm -qa |grep vim vim-X11-7.4.629-8.el7_9.x
修改hadoop配置 vi /usr/local/software/hadoop-2.9.2/etc/hadoop/yarn-site.xml # 添加如下 <configuration> <property> <name>yarn.nodemanager.res