树莓派安装opencv
时间: 2023-06-20 14:05:50 浏览: 109
树莓派OpenCV安装
5星 · 资源好评率100%
安装OpenCV可以让树莓派进行图像处理和计算机视觉任务。下面是在树莓派上安装OpenCV的简单教程:
1. 更新树莓派软件包列表和系统:
```
sudo apt-get update
sudo apt-get upgrade
```
2. 安装OpenCV依赖项:
```
sudo apt-get install build-essential cmake pkg-config
sudo apt-get install libjpeg-dev libtiff5-dev libjasper-dev libpng-dev libwebp-dev libopenexr-dev
sudo apt-get install libavcodec-dev libavformat-dev libswscale-dev libv4l-dev libxvidcore-dev libx264-dev
sudo apt-get install libgtk-3-dev libatlas-base-dev gfortran
```
3. 下载OpenCV源代码并解压:
```
wget -O opencv.zip https://github.com/opencv/opencv/archive/master.zip
unzip opencv.zip
```
4. 进入解压后的目录并创建build目录:
```
cd opencv-master
mkdir build
cd build
```
5. 配置OpenCV编译选项:
```
cmake -D CMAKE_BUILD_TYPE=RELEASE \
-D CMAKE_INSTALL_PREFIX=/usr/local \
-D INSTALL_C_EXAMPLES=ON \
-D INSTALL_PYTHON_EXAMPLES=ON \
-D WITH_TBB=ON \
-D WITH_V4L=ON \
-D WITH_QT=OFF \
-D WITH_OPENGL=ON \
-D OPENCV_EXTRA_MODULES_PATH=~/opencv_contrib/modules \
-D BUILD_EXAMPLES=ON ..
```
6. 编译并安装OpenCV:
```
make -j4
sudo make install
sudo ldconfig
```
7. 安装完成后,可以在Python中导入OpenCV进行测试:
```
import cv2
```
如果没有报错,说明OpenCV已经成功安装。
阅读全文