赞
踩
按照这一篇进行树莓派4b安装opencv-python详细过程。
这段代码会显示如下的报错:
解决方案:(后面要加两个 .. )
- cmake -D CMAKE_BUILD_TYPE=RELEASE \
- -D CMAKE_INSTALL_PREFIX=/usr/local \
- -D INSTALL_C_EXAMPLES=ON \
- -D INSTALL_PYTHON_EXAMPLES=ON \
- -D OPENCV_EXTRA_MODULES_PATH=/home/astray/opencv_contrib-4.1.0/modules \#本行需根据自己安装的路径修改
- -D BUILD_EXAMPLES=ON \
- -D WITH_LIBV4L=ON \
- -D PYTHON3_EXECUTABLE=/usr/bin/python3.7 \
- -D PYTHON_INCLUDE_DIR=/usr/include/python3.7 \
- -D PYTHON_LIBRARY=/usr/lib/arm-linux-gnueabihf/libpython3.7m.so \
- -D PYTHON3_NUMPY_INCLUDE_DIRS=/usr/lib/python3/dist-packages/numpy/core/include \
- .. ####这两个点至关重要!!!!
之后可以继续下去了,这是又碰到了第二个问题。
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,出现好多函数被移除和修改的错误,改起来太麻烦就放弃了。。。
创建虚拟环境
- python3 -m venv test_env
- source ./test_env/bin/activate //激活虚拟环境
sudo pip3 install numpy
- sudo apt-get install build-essential git cmake pkg-config -y
- sudo apt install libwebpmux3 libssl3 libva-drm2 libxfixes3
- sudo apt install libcairo-gobject2 libvpx7 libvorbisenc2 libxcb-shm0 libxcb-render0
- sudo apt install libwayland-client0 libhwy1 libicu72
- sudo apt install libjbig0 libaom3 libwebp7 libxdamage1 libxcb-dri3-0
- sudo apt install libsvtav1enc1 libfreetype6 libfribidi0 libsrt1.5-gnutls
- sudo apt install libgcrypt20 libcairo2 libavutil57 librabbitmq4 libepoxy0
- sudo apt install libxrender1 libidn2-0 libsystemd0 libpango-1.0-0 libatk1.0-0 libzvbi0
- sudo apt install libcodec2-1.0 libvdpau1 libavformat59 libchromaprint1 libdatrie1
- sudo apt install libxcursor1 libatk-bridge2.0-0 libharfbuzz0b libp11-kit0
- sudo apt install libxvidcore4 libglib2.0-0 libogg0 libnorm1
- sudo apt install libtheora0 libmp3lame0 libx265-199 libsnappy1v5 libgme0 libopenmpt0
- sudo apt install libmpg123-0 libgfortran5 libxinerama1 libxdmcp6
- sudo apt install libxrandr2 libx11-xcb1 libxext6 libbluray2 libstdc++6 libdrm2 libva2
- sudo apt install libatspi2.0-0 libswscale6 ocl-icd-libopencl1 libva-x11-2
- sudo apt install libpgm-5.3-0 libxcb1 libk5crypto3 liblz4-1
- sudo apt install libnettle8 libmd0 libjpeg62-turbo libgomp1 libsodium23 libwayland-egl1
- sudo apt install librist4 libudfread0 libxkbcommon0 libtiff6 libatomic1
- sudo apt install libssh-gcrypt-4 libhogweed6 libxml2 libthai0 librsvg2-2
- sudo apt install libspeex1 libswresample4 libsoxr0 libfontconfig1 libgdk-pixbuf-2.0-0
- sudo apt install libmount1 libffi8 libtasn1-6 libx264-164 libkrb5-3 libzmq5 libzstd1
- sudo apt install libxcomposite1 libgnutls30 libpixman-1-0 libgraphite2-3 libgtk-3-0
- sudo apt install libwayland-cursor0 libshine3 libtwolame0
- sudo apt install libpng16-16 libgssapi-krb5-2 libdav1d6 libgmp10
- sudo apt install libpangocairo-1.0-0 libpcre2-8-0 libgsm1 libavcodec59 libxau6
- sudo apt install libvorbisfile3 libjxl0.7 libunistring2 libatlas3-base
- sudo apt install liblerc4 libopus0 libcjson1 libmbedcrypto7 libbrotli1 libxi6
- sudo apt install libpangoft2-1.0-0 liblcms2-2 libblkid1 libdeflate0
- sudo apt install libopenjp2-7 libvorbis0a libkrb5support0 librav1e0 libbsd0 libx11-6
-
- pip3 install opencv-python
- pip3 install opencv-contrib-python
查了原因还是版本不兼容问题,安装都是最新版的不稳定
尝试降级python 完全照着gpt来
- sudo apt-get update
- sudo apt-get install -y make build-essential libssl-dev zlib1g-dev libbz2-dev \
- libreadline-dev libsqlite3-dev wget curl llvm libncurses5-dev libncursesw5-dev \
- xz-utils tk-dev libffi-dev liblzma-dev python-openssl git
curl https://pyenv.run | bash
- export PATH="~/.pyenv/bin:$PATH"
- eval "$(pyenv init -)"
- eval "$(pyenv virtualenv-init -)"
source ~/.bashrc
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。