ubuntu20.04安装opencv3.4.1
时间: 2023-05-01 13:00:30 浏览: 217
Ubuntu20.04安装opencv4.4.0+opencv-contrib4.4.0 缺失文件
Ubuntu 20.04 上安装 OpenCV 3.4.1 的步骤如下:
1. 安装依赖:
```
sudo apt update
sudo apt upgrade
sudo apt install build-essential cmake unzip pkg-config libjpeg-dev libpng-dev libtiff-dev libavcodec-dev libavformat-dev libswscale-dev libv4l-dev libxvidcore-dev libx264-dev libgtk-3-dev libatlas-base-dev gfortran python3-dev
```
2. 下载 OpenCV 源码:
```
wget -O opencv.zip https://github.com/opencv/opencv/archive/3.4.1.zip
wget -O opencv_contrib.zip https://github.com/opencv/opencv_contrib/archive/3.4.1.zip
unzip opencv.zip
unzip opencv_contrib.zip
```
3. 编译并安装 OpenCV:
```
cd opencv-3.4.1
mkdir build
cd build
cmake -D CMAKE_BUILD_TYPE=RELEASE \
-D CMAKE_INSTALL_PREFIX=/usr/local \
-D INSTALL_PYTHON_EXAMPLES=ON \
-D INSTALL_C_EXAMPLES=OFF \
-D OPENCV_ENABLE_NONFREE=ON \
-D OPENCV_EXTRA_MODULES_PATH=../../opencv_contrib-3.4.1/modules \
-D PYTHON_EXECUTABLE=$(which python3) \
-D BUILD_EXAMPLES=ON ..
make -j4
sudo make install
sudo ldconfig
```
4. 验证安装:
```
python3
>>> import cv2
>>> print(cv2.__version__)
```
如果输出了 "3.4.1",则说明安装成功。
阅读全文