ubuntu24.04安装opencv
时间: 2024-07-23 17:01:34 浏览: 524
在Ubuntu 24.04上安装OpenCV通常需要几个步骤,因为默认的包管理器apt可能没有包含最新版本的OpenCV。以下是安装过程:
1. 更新系统:
```sh
sudo apt update && sudo apt upgrade
```
2. 添加OpenCV PPA (个人软件包存档):
```sh
sudo add-apt-repository ppa:ubuntu-toolchain-r/test -y
sudo apt install software-properties-common
sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys E084DAB9
echo "deb [arch=amd64] https://developer.download.nvidia.com/compute/cuda/repos/ubuntu2004/x86_64/ $(lsb_release -cs) main" | sudo tee /etc/apt/sources.list.d/cuda.list
sudo apt-get update
```
3. 安装依赖项(对于GPU支持):
对于CPU版本:
```sh
sudo apt install libgtk-3-dev swig python3-dev build-essential cmake 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
```
对于CUDA支持(如果你有GPU):
```sh
sudo apt-get install cuda
```
4. 获取并安装OpenCV:
```sh
sudo apt-get install python3-opencv
```
或者使用pip安装:
```sh
pip3 install opencv-python
```
5. 验证安装:
运行 `python3 -c "import cv2; print(cv2.__version__)"` 来确认OpenCV是否成功安装。
阅读全文