树莓派4B32位系统如何安装opencv-python
时间: 2024-05-17 18:06:46 浏览: 214
你可以按照以下步骤在树莓派4B的32位系统上安装opencv-python:
1. 打开终端,更新树莓派软件包列表:
```
sudo apt-get update
```
2. 安装依赖项:
```
sudo apt-get install build-essential cmake pkg-config libjpeg-dev libtiff5-dev libjasper-dev libpng-dev libavcodec-dev libavformat-dev libswscale-dev libv4l-dev libxvidcore-dev libx264-dev libgtk2.0-dev libgtk-3-dev libatlas-base-dev gfortran python3-dev python3-numpy libtbb2 libtbb-dev libdc1394-22-dev
```
3. 下载OpenCV源代码:
```
wget -O opencv.zip https://github.com/opencv/opencv/archive/4.5.1.zip
wget -O opencv_contrib.zip https://github.com/opencv/opencv_contrib/archive/4.5.1.zip
```
4. 解压缩下载的文件:
```
unzip opencv.zip
unzip opencv_contrib.zip
```
5. 创建构建目录并进入:
```
mkdir -p ~/opencv_build && cd ~/opencv_build
```
6. 配置构建:
```
cmake -D CMAKE_BUILD_TYPE=RELEASE \
-D CMAKE_INSTALL_PREFIX=/usr/local \
-D OPENCV_EXTRA_MODULES_PATH=~/opencv_contrib-4.5.1/modules \
-D ENABLE_NEON=ON \
-D WITH_OPENMP=ON \
-D WITH_OPENGL=ON \
-D WITH_QT=OFF \
-D BUILD_EXAMPLES=OFF \
-D PYTHON3_EXECUTABLE=/usr/bin/python3 \
-D PYTHON_INCLUDE_DIR=/usr/include/python3.7 \
-D PYTHON_INCLUDE_DIR2=/usr/include/arm-linux-gnueabihf/python3.7m \
-D PYTHON_LIBRARY=/usr/lib/arm-linux-gnueabihf/libpython3.7m.so \
-D PYTHON3_NUMPY_INCLUDE_DIRS=/usr/lib/python3/dist-packages/numpy/core/include \
-D BUILD_opencv_python2=OFF \
-D BUILD_opencv_python3=ON \
-D BUILD_TESTS=OFF \
-D BUILD_PERF_TESTS=OFF ..
```
7. 编译并安装:
```
make -j4
sudo make install
sudo ldconfig
```
8. 安装OpenCV Python包:
```
pip3 install opencv-python
```
安装完成后,你就可以在树莓派上使用OpenCV Python包了。
阅读全文