在树莓派上安装OpenCV-Python
时间: 2024-04-09 19:21:10 浏览: 84
安装OpenCV-Python可以通过以下步骤在树莓派上完成:
1. 安装依赖项:
```
sudo apt-get update
sudo apt-get install build-essential cmake pkg-config
sudo apt-get install libjpeg-dev libtiff5-dev libjasper-dev libpng12-dev
sudo apt-get install libavcodec-dev libavformat-dev libswscale-dev libv4l-dev
sudo apt-get install libxvidcore-dev libx264-dev
sudo apt-get install libgtk2.0-dev libgtk-3-dev
sudo apt-get install libatlas-base-dev gfortran
```
2. 下载OpenCV:
```
cd ~
wget -O opencv.zip https://github.com/opencv/opencv/archive/4.0.0.zip
wget -O opencv_contrib.zip https://github.com/opencv/opencv_contrib/archive/4.0.0.zip
unzip opencv.zip
unzip opencv_contrib.zip
```
3. 创建并进入构建目录:
```
cd ~/opencv-4.0.0/
mkdir build
cd build
```
4. 配置OpenCV:
```
cmake -D CMAKE_BUILD_TYPE=RELEASE \
-D CMAKE_INSTALL_PREFIX=/usr/local \
-D OPENCV_EXTRA_MODULES_PATH=~/opencv_contrib-4.0.0/modules \
-D ENABLE_NEON=ON \
-D ENABLE_VFPV3=ON \
-D BUILD_TESTS=OFF \
-D INSTALL_PYTHON_EXAMPLES=OFF \
-D BUILD_EXAMPLES=OFF ..
```
5. 编译并安装OpenCV:
```
make -j4
sudo make install
sudo ldconfig
```
6. 验证OpenCV是否安装成功:
```
python
import cv2
print(cv2.__version__)
```
如果没有报错,就说明OpenCV-Python已经安装成功了。
阅读全文