在树莓派上安装opencv
时间: 2023-10-10 16:08:52 浏览: 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
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
sudo apt-get install libgtk2.0-dev libgtk-3-dev
sudo apt-get install libatlas-base-dev gfortran
sudo apt-get install python3-dev
```
3. 下载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
```
4. 创建并进入一个build目录:
```
cd ~/opencv-4.5.1/
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.5.1/modules \
-D ENABLE_NEON=ON \
-D ENABLE_VFPV3=ON \
-D BUILD_TESTS=OFF \
-D INSTALL_PYTHON_EXAMPLES=OFF \
-D OPENCV_ENABLE_NONFREE=ON \
-D CMAKE_SHARED_LINKER_FLAGS=-latomic \
-D BUILD_EXAMPLES=OFF ..
```
6. 编译和安装OpenCV:
```
make -j4
sudo make install
sudo ldconfig
```
安装完成后,您可以检查OpenCV是否正确安装。在终端中输入以下命令:
```
pkg-config --modversion opencv4
```
如果安装成功,它将返回安装的OpenCV版本号。
注意:安装OpenCV需要一定的时间和硬件资源,因此请耐心等待。
阅读全文