64位和32位的 bullseye 都用过了,发现还是对现有的包支持的不够好,现在从头开始,希望为时不晚。
Raspberry Pi OS(32位)buster 的 Legacy 版本:下载地址
安装顺序:Qt5 -> Eigen 3.4.0 -> OpenCV 4.5.5 -> ncnn
sudo apt-get update
sudo apt-get dist-upgrade
sudo apt-get update
sudo apt-get upgrade
sudo apt-get install clang clang-format
sudo apt-get install qt5-default
sudo apt-get install qtcreator
sudo apt-get install qtdeclarative5-dev
还要把下面的gtk3改成gtk2
sudo nano /etc/xdg/qt5ct/qt5ct.conf
也是采用编译安装,能安装上最新版本。
先去官网下载最新版本:Eigen下载地址
下载后解压并重命名到主目录:
unzip eigen-3.4.0.zip
mv eigen-3.4.0 ~/eigen
cd eigen
mkdir build
cd build
cmake ..
make -j4
sudo make install
sudo ldconfig
sudo reboot
So easyyyy!
先把树莓派GPU显存改成128MB
再把swap-memory改成4096MB,需要把最大限制和当前值都改了
改完然后重启。
最后把树莓派的eeprom更新一下,有利于降温,改完也要重启
sudo rpi-eeprom-update -a
sudo reboot
GitHub - opencv/opencv_contrib 下载地址
下载、解压、重命名。
unzip opencv-4.5.5.zip
unzip opencv_contrib-4.5.5.zip
mv opencv-4.5.5 ~/opencv
mv opencv_contrib-4.5.5 ~/opencv_contrib
安装依赖
sudo apt-get update
sudo apt-get upgrade
sudo apt-get install cmake gfortran
sudo apt-get install python3-dev python3-numpy
sudo apt-get install libjpeg-dev libtiff-dev libgif-dev
sudo apt-get install libgstreamer1.0-dev gstreamer1.0-gtk3
sudo apt-get install libgstreamer-plugins-base1.0-dev gstreamer1.0-gl
sudo apt-get install libavcodec-dev libavformat-dev libswscale-dev
sudo apt-get install libgtk2.0-dev libcanberra-gtk*
sudo apt-get install libxvidcore-dev libx264-dev libgtk-3-dev
sudo apt-get install libtbb2 libtbb-dev libdc1394-22-dev libv4l-dev
sudo apt-get install libopenblas-dev libatlas-base-dev libblas-dev
sudo apt-get install libjasper-dev liblapack-dev libhdf5-dev
sudo apt-get install protobuf-compiler
由于 buster 仍然是 Python3 和 Python2 共存,所以还需要安装 Python2 的依赖
sudo apt-get install python-dev python-numpy
编译安装
cd opencv
mkdir build
cd build
此时最好把cmake过程中需要下载的文件全部预先下载好,并放在opencv/.cache目录下,该目录默认是隐藏的,我下载了一份最最完整的,云盘链接放在这里:
链接:https://pan.xunlei.com/s/VN9GfwEr1OdUpu85HZ23vrR2A1#
提取码:xcmd
unzip cache.zip
mv cache ~/opencv/.cache
然后cmake
cmake -D CMAKE_BUILD_TYPE=RELEASE \
-D CMAKE_INSTALL_PREFIX=/usr/local \
-D OPENCV_EXTRA_MODULES_PATH=~/opencv_contrib/modules \
-D ENABLE_NEON=ON \
-D ENABLE_VFPV3=ON \
-D WITH_OPENMP=ON \
-D WITH_OPENCL=OFF \
-D BUILD_ZLIB=ON \
-D BUILD_TIFF=ON \
-D WITH_FFMPEG=ON \
-D WITH_TBB=ON \
-D BUILD_TBB=ON \
-D BUILD_TESTS=OFF \
-D WITH_EIGEN=ON \
-D WITH_GSTREAMER=ON \
-D WITH_V4L=ON \
-D WITH_LIBV4L=ON \
-D WITH_VTK=OFF \
-D WITH_QT=ON \
-D OPENCV_ENABLE_NONFREE=ON \
-D INSTALL_C_EXAMPLES=OFF \
-D INSTALL_PYTHON_EXAMPLES=OFF \
-D PYTHON3_PACKAGES_PATH=/usr/lib/python3/dist-packages \
-D OPENCV_GENERATE_PKGCONFIG=ON \
-D BUILD_EXAMPLES=OFF ..
make -j4
sudo make install
sudo ldconfig
sudo reboot
sudo apt-get update
sudo apt-get upgrade
sudo apt-get install cmake wget
sudo apt-get install libprotobuf-dev protobuf-compiler
unzip ncnn-master.zip
mv ncnn-master ~/ncnn
cd ncnn
mkdir build
cd build
cmake -D PI3=ON \
-D NCNN_DISABLE_RTTI=OFF \
-D CMAKE_EXE_LINKER_FLAGS=-ldl \
-D CMAKE_TOOLCHAIN_FILE=../toolchains/pi3.toolchain.cmake ..
make -j4
sudo make install
sudo ldconfig
ncnn 的文件都安装在 build 下的 install 里面了,需要复制到 /usr/local
sudo cp -r install/lib/cmake/ncnn /usr/local/lib/cmake/
sudo mkdir /usr/local/lib/ncnn
sudo cp install/lib/libncnn.a /usr/local/lib/ncnn/
sudo cp -r install/include/ncnn /usr/local/include/
sudo cp -r install/bin/* /usr/local/bin/
大功告成!