ubuntu安装opencv-4.8.0.tar.gz
时间: 2024-12-23 18:18:52 浏览: 8
在Ubuntu上安装OpenCV 4.8.0可以从源码编译开始,因为预编译的包可能与系统的其他依赖版本不匹配。以下是安装步骤:
1. **更新系统和安装依赖**:
```
sudo apt-get update
sudo apt-get install -y build-essential cmake git libgtk-3-dev pkg-config libavcodec-dev libavformat-dev libswscale-dev libv4l-dev \
libxvidcore-dev x264 v4l-utils libjpeg-dev libpng-dev libtiff-dev libjasper-dev python3-dev python3-pip libdc1394-22-dev \
libusb-1.0-0-dev libudev-dev libblas-dev liblapack-dev gfortran
```
2. **下载并解压OpenCV源码**:
```
wget https://github.com/opencv/opencv/archive/4.8.0.tar.gz
tar -xzvf opencv-4.8.0.tar.gz
cd opencv-4.8.0
```
3. **配置OpenCV**:
```
mkdir build
cd build
cmake ..
```
如果有缺失的库或错误,可能需要添加`-D ENABLE.opencv_python=ON`选项,并指定Python路径,如 `-DPYTHON_EXECUTABLE=/usr/bin/python3`。
4. **编译和安装**:
```
make -j$(nproc) # 使用所有可用处理器进行并行编译
sudo make install
```
5. **检查安装**:
验证OpenCV是否成功安装:
```
python3 -c "import cv2; print(cv2.__version__)"
```
阅读全文