当前位置:   article > 正文

树莓派-python3.11 记录opencv 安装过程遇到问题_树莓派4b安装opencv python3.11.2

树莓派4b安装opencv python3.11.2

按照这一篇进行树莓派4b安装opencv-python详细过程

方法一:大通过编译安装,其中会遇到不少问题,之前安装过一遍走通过一次,但是python版本高了之后遇到很多问题。目前没走通,给出解决方案以供参考。

 在4.配置cmake时遇到第一个问题,

这段代码会显示如下的报错:

解决方案:(后面要加两个 .. )

  1. cmake -D CMAKE_BUILD_TYPE=RELEASE \
  2. -D CMAKE_INSTALL_PREFIX=/usr/local \
  3. -D INSTALL_C_EXAMPLES=ON \
  4. -D INSTALL_PYTHON_EXAMPLES=ON \
  5. -D OPENCV_EXTRA_MODULES_PATH=/home/astray/opencv_contrib-4.1.0/modules \#本行需根据自己安装的路径修改
  6. -D BUILD_EXAMPLES=ON \
  7. -D WITH_LIBV4L=ON \
  8. -D PYTHON3_EXECUTABLE=/usr/bin/python3.7 \
  9. -D PYTHON_INCLUDE_DIR=/usr/include/python3.7 \
  10. -D PYTHON_LIBRARY=/usr/lib/arm-linux-gnueabihf/libpython3.7m.so \
  11. -D PYTHON3_NUMPY_INCLUDE_DIRS=/usr/lib/python3/dist-packages/numpy/core/include \
  12. .. ####这两个点至关重要!!!!

之后可以继续下去了,这是又碰到了第二个问题。

CMake Error at cmake/OpenCVCompilerOptions.cmake:477 (else):
Flow control statements are not properly nested.
Call Stack (most recent call first):
CMakeLists.txt:692 (include)

解决方案:参照这一篇https://blog.csdn.net/qq_57061492/article/details/126171010

将opencv文件夹中的 cmake/OpenCVCompilerOptimizations.cmake打开 (记得sudo) 找到477那一行把那一段代码注释掉。

配置成功会显示:

继续进行make,出现第三个问题:

c++: error: unrecognized command-line option ‘--param=ipcp-unit-growth=100000’; did you mean ‘--param=ipa-cp-unit-growth=’?

解决方案:参考https://blog.csdn.net/jiugeshao/article/details/121522829

修改提示目录下的文件,并把'ipcp-unit-growth'替换为'ipa-cp-unit-growth'

后续出现用新版ffmeg/libav编译旧版opencv,出现好多函数被移除和修改的错误,改起来太麻烦就放弃了。。。

方法二:(2023.10.16终于跑通了记录安装过程)

针对树莓派终端不能直接pip install问题

创建虚拟环境

  1. python3 -m venv test_env
  2. source ./test_env/bin/activate //激活虚拟环境

安装依赖库:piwheels - opencv-pythonhttps://www.piwheels.org/project/opencv-contrib-python/

sudo pip3 install numpy
  1. sudo apt-get install build-essential git cmake pkg-config -y
  2. sudo apt install libwebpmux3 libssl3 libva-drm2 libxfixes3
  3. sudo apt install libcairo-gobject2 libvpx7 libvorbisenc2 libxcb-shm0 libxcb-render0
  4. sudo apt install libwayland-client0 libhwy1 libicu72
  5. sudo apt install libjbig0 libaom3 libwebp7 libxdamage1 libxcb-dri3-0
  6. sudo apt install libsvtav1enc1 libfreetype6 libfribidi0 libsrt1.5-gnutls
  7. sudo apt install libgcrypt20 libcairo2 libavutil57 librabbitmq4 libepoxy0
  8. sudo apt install libxrender1 libidn2-0 libsystemd0 libpango-1.0-0 libatk1.0-0 libzvbi0
  9. sudo apt install libcodec2-1.0 libvdpau1 libavformat59 libchromaprint1 libdatrie1
  10. sudo apt install libxcursor1 libatk-bridge2.0-0 libharfbuzz0b libp11-kit0
  11. sudo apt install libxvidcore4 libglib2.0-0 libogg0 libnorm1
  12. sudo apt install libtheora0 libmp3lame0 libx265-199 libsnappy1v5 libgme0 libopenmpt0
  13. sudo apt install libmpg123-0 libgfortran5 libxinerama1 libxdmcp6
  14. sudo apt install libxrandr2 libx11-xcb1 libxext6 libbluray2 libstdc++6 libdrm2 libva2
  15. sudo apt install libatspi2.0-0 libswscale6 ocl-icd-libopencl1 libva-x11-2
  16. sudo apt install libpgm-5.3-0 libxcb1 libk5crypto3 liblz4-1
  17. sudo apt install libnettle8 libmd0 libjpeg62-turbo libgomp1 libsodium23 libwayland-egl1
  18. sudo apt install librist4 libudfread0 libxkbcommon0 libtiff6 libatomic1
  19. sudo apt install libssh-gcrypt-4 libhogweed6 libxml2 libthai0 librsvg2-2
  20. sudo apt install libspeex1 libswresample4 libsoxr0 libfontconfig1 libgdk-pixbuf-2.0-0
  21. sudo apt install libmount1 libffi8 libtasn1-6 libx264-164 libkrb5-3 libzmq5 libzstd1
  22. sudo apt install libxcomposite1 libgnutls30 libpixman-1-0 libgraphite2-3 libgtk-3-0
  23. sudo apt install libwayland-cursor0 libshine3 libtwolame0
  24. sudo apt install libpng16-16 libgssapi-krb5-2 libdav1d6 libgmp10
  25. sudo apt install libpangocairo-1.0-0 libpcre2-8-0 libgsm1 libavcodec59 libxau6
  26. sudo apt install libvorbisfile3 libjxl0.7 libunistring2 libatlas3-base
  27. sudo apt install liblerc4 libopus0 libcjson1 libmbedcrypto7 libbrotli1 libxi6
  28. sudo apt install libpangoft2-1.0-0 liblcms2-2 libblkid1 libdeflate0
  29. sudo apt install libopenjp2-7 libvorbis0a libkrb5support0 librav1e0 libbsd0 libx11-6

安装opencv、opencv-contrib-python

  1. pip3 install opencv-python
  2. pip3 install opencv-contrib-python

要等很久很久才能成功。 (吐了,安装成功不能正常使用服了。。。)

查了原因还是版本不兼容问题,安装都是最新版的不稳定

尝试降级python 完全照着gpt来

  1. sudo apt-get update
  2. sudo apt-get install -y make build-essential libssl-dev zlib1g-dev libbz2-dev \
  3. libreadline-dev libsqlite3-dev wget curl llvm libncurses5-dev libncursesw5-dev \
  4. xz-utils tk-dev libffi-dev liblzma-dev python-openssl git
curl https://pyenv.run | bash
  1. export PATH="~/.pyenv/bin:$PATH"
  2. eval "$(pyenv init -)"
  3. eval "$(pyenv virtualenv-init -)"
source ~/.bashrc

行不通啊。。再写一篇吧,终于安装成功了。

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/从前慢现在也慢/article/detail/176905
推荐阅读
相关标签
  

闽ICP备14008679号