树莓派安装opencv
时间: 2023-10-10 12:15:35 浏览: 106
安装 OpenCV 可以使树莓派具备图像处理和计算机视觉能力。以下是在树莓派上安装 OpenCV 的步骤:
1. 更新树莓派软件包列表:
```
sudo apt-get update
```
2. 安装 OpenCV 所需的依赖项:
```
sudo apt-get install build-essential cmake pkg-config libjpeg-dev libtiff5-dev libjasper-dev libpng12-dev libavcodec-dev libavformat-dev libswscale-dev libv4l-dev libxvidcore-dev libx264-dev libatlas-base-dev gfortran python3-dev python3-numpy libgtk2.0-dev libgtk-3-dev libdc1394-22-dev libopencv-dev libgstreamer1.0-dev libgstreamer-plugins-base1.0-dev libqt4-dev
```
3. 下载 OpenCV 源代码:
```
cd ~
wget -O opencv.zip https://github.com/opencv/opencv/archive/4.1.0.zip
wget -O opencv_contrib.zip https://github.com/opencv/opencv_contrib/archive/4.1.0.zip
unzip opencv.zip
unzip opencv_contrib.zip
```
4. 创建一个 build 目录并进入该目录:
```
cd opencv-4.1.0
mkdir build
cd build
```
5. 配置 OpenCV:
```
cmake -D CMAKE_BUILD_TYPE=RELEASE \
-D CMAKE_INSTALL_PREFIX=/usr/local \
-D OPENCV_EXTRA_MODULES_PATH=~/opencv_contrib-4.1.0/modules \
-D BUILD_EXAMPLES=ON \
-D ENABLE_NEON=ON \
-D WITH_LIBV4L=ON \
-D WITH_OPENGL=ON \
-D WITH_TBB=ON \
-D BUILD_TBB=ON \
-D WITH_QT=ON \
-D BUILD_opencv_python3=yes \
-D BUILD_opencv_python2=no \
-D PYTHON_DEFAULT_EXECUTABLE=/usr/bin/python3 \
-D BUILD_PERF_TESTS=OFF \
-D BUILD_TESTS=OFF \
../
```
6. 编译 OpenCV:
```
make -j4
```
7. 安装 OpenCV:
```
sudo make install
sudo ldconfig
```
完成后,您的树莓派就可以使用 OpenCV 了。
阅读全文