ubuntu18.04 opencv安装教程
时间: 2024-09-27 07:00:49 浏览: 37
在Ubuntu 18.04上安装OpenCV,可以按照以下步骤进行:
1. **更新包列表**:
```
sudo apt update
```
2. **安装依赖库**:
```
sudo apt install build-essential cmake libgtk-3-dev pkg-config libavcodec-dev libavformat-dev libswscale-dev libv4l-dev libxvidcore-dev libx264-dev libjpeg-dev libpng-dev libtiff-dev libjasper-dev libdc1394-22-dev libopenblas-dev libatlas-base-dev gfortran
```
3. **下载OpenCV源码**:
```
wget -O opencv.zip https://github.com/opencv/opencv/archive/4.x.zip
unzip opencv.zip
cd opencv-4.x
```
4. **配置安装**:
```
mkdir build
cd build
cmake ..
```
如果有其他自定义需求,可以添加选项如 `-DWITH_CUDA=ON` 或 `-DBUILD_opencv_java=ON` 等。
5. **编译并安装**:
```
sudo make -j$(nproc) # 使用所有CPU核心加速编译
sudo make install
```
6. **检查安装**:
```
which python3-opencv # 查看Python绑定是否安装成功
opencv_version=$(python3 -c "import cv2; print(cv2.__version__)")
```
7. **清理临时文件**:
```
cd ..
rm -rf opencv.zip build
```
阅读全文