树莓派安装opencv
时间: 2023-08-13 07:06:57 浏览: 131
好的,以下是安装 OpenCV 的步骤:
1. 更新系统软件包:
```
sudo apt-get update
sudo apt-get upgrade
```
2. 安装 OpenCV 所需依赖:
```
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 libcanberra-gtk* libatlas-base-dev gfortran python3-dev python3-numpy python3-pip
```
3. 下载 OpenCV 源代码:
```
cd ~
wget -O opencv.zip https://github.com/opencv/opencv/archive/master.zip
wget -O opencv_contrib.zip https://github.com/opencv/opencv_contrib/archive/master.zip
unzip opencv.zip
unzip opencv_contrib.zip
```
4. 编译并安装 OpenCV:
```
cd ~/opencv-master
mkdir build
cd build
cmake -D CMAKE_BUILD_TYPE=RELEASE -D CMAKE_INSTALL_PREFIX=/usr/local -D OPENCV_EXTRA_MODULES_PATH=~/opencv_contrib-master/modules -D ENABLE_NEON=ON -D WITH_LIBV4L=ON -D BUILD_opencv_python3=yes -D BUILD_opencv_python2=no -D PYTHON3_EXECUTABLE=/usr/bin/python3 -D PYTHON_INCLUDE_DIR=/usr/include/python3.7m -D PYTHON3_NUMPY_INCLUDE_DIRS=/usr/lib/python3/dist-packages/numpy/core/include/ ..
make -j4
sudo make install
sudo ldconfig
```
5. 检查 OpenCV 是否安装成功:
```
python3 -c "import cv2; print(cv2.__version__)"
```
如果输出 OpenCV 版本号,则说明安装成功。
希望这可以帮助你成功安装 OpenCV。
阅读全文