当前位置: 首页 > 工具软件 > iot4j > 使用案例 >

树莓派4b安装windows iot_树莓派4B基于python3安装opencv4全教程

诸修伟
2023-12-01

昨天有同学私信说编译几个小时安装太麻烦,有没有简单点的方法,现在提供两种安装方法

我的环境

  • 树莓派4B
  • python = 3.7.3
  • 操作系统,2020-3 官方最新镜像

1.换国内源(详细步骤看我以前的教程)安装依赖

sudo apt-get update && sudo apt-get upgrade
sudo apt-get install build-essential cmake pkg-config -y
sudo apt-get install libjpeg-dev libtiff5-dev libjasper-dev libpng-dev -y
sudo apt-get install libavcodec-dev libavformat-dev libswscale-dev libv4l-dev -y
sudo apt-get install libxvidcore-dev libx264-dev -y
sudo apt-get install libfontconfig1-dev libcairo2-dev -y
sudo apt-get install libgdk-pixbuf2.0-dev libpango1.0-dev -y
sudo apt-get install libgtk2.0-dev libgtk-3-dev -y
sudo apt-get install libatlas-base-dev gfortran -y

# 
sudo apt-get install libhdf5-dev libhdf5-serial-dev libhdf5-103 -y
sudo apt-get install libqtgui4 libqtwebkit4 libqt4-test python3-pyqt5

2.安装numpy

pip install numpy

3A. 简单安装,适合新手,几分钟即可安装完毕,但是一定要注意安装这个版本的包,使用其它版本号可能会引起失败

 pip install opencv-contrib-python==4.1.0.25
Python 3.7.3
[GCC 8.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import cv2
>>> cv2.__init__
<method-wrapper '__init__' of module object at 0xb68e4690>
>>> cv2.__version__
'4.1.0'

3B.编译安装,如果编译出错 :memory exhausting,可以把swap提高到2048MB

$ cd ~
$ wget -O opencv.zip https://github.com/opencv/opencv/archive/4.1.1.zip
$ wget -O opencv_contrib.zip https://github.com/opencv/opencv_contrib/archive/4.1.1.zip
$ unzip opencv.zip
$ unzip opencv_contrib.zip
$ mv opencv-4.1.1 opencv
$ mv opencv_contrib-4.1.1 opencv_contrib

$ cd ~/opencv
$ mkdir build
$ cd build
$ 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 BUILD_TESTS=OFF 
    -D INSTALL_PYTHON_EXAMPLES=OFF 
    -D OPENCV_ENABLE_NONFREE=ON 
    -D CMAKE_SHARED_LINKER_FLAGS=-latomic 
    -D BUILD_EXAMPLES=OFF ..

$ make -j4
$ sudo make install
$ sudo ldconfig
 类似资料: