树莓派安装opencv
时间: 2023-08-16 10:06:54 浏览: 95
好的,以下是树莓派安装 OpenCV 的步骤:
1. 更新树莓派软件包列表
打开终端,运行以下命令:
```
sudo apt-get update
```
2. 安装依赖项
运行以下命令安装依赖项:
```
sudo apt-get install build-essential cmake pkg-config
sudo apt-get install libjpeg-dev libtiff5-dev libjasper-dev libpng-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 libfontconfig1-dev libcairo2-dev
sudo apt-get install libgdk-pixbuf2.0-dev libpango1.0-dev libgtk2.0-dev libgtk-3-dev
sudo apt-get install libatlas-base-dev gfortran
```
3. 下载并安装 OpenCV
下载 OpenCV 的源代码:
```
cd ~
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
unzip opencv.zip
unzip opencv_contrib.zip
```
编译并安装 OpenCV:
```
cd ~/opencv-4.5.1/
mkdir build
cd build
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_FFMPEG=ON \
-D WITH_TBB=ON \
-D BUILD_TBB=ON \
-D BUILD_TESTS=OFF \
-D WITH_EIGEN=OFF \
-D WITH_V4L=ON \
-D WITH_LIBV4L=ON \
-D WITH_OPENGL=ON \
-D WITH_CUDA=OFF \
-D BUILD_PERF_TESTS=OFF \
-D BUILD_opencv_java=OFF \
-D WITH_GTK=ON \
-D BUILD_EXAMPLES=OFF ..
```
编译 OpenCV:
```
make -j4
```
安装 OpenCV:
```
sudo make install
sudo ldconfig
```
4. 测试 OpenCV
运行以下命令测试 OpenCV 是否安装成功:
```
python3
>>> import cv2
>>> cv2.__version__
```
如果输出了 OpenCV 的版本号,则说明安装成功。
希望这些步骤能对你安装 OpenCV 有所帮助。
阅读全文