ubuntu20.04安装opencv和contrib
时间: 2023-09-16 13:05:48 浏览: 274
Ubuntu20.04安装opencv4.4.0+opencv-contrib4.4.0 缺失文件
### 回答1:
安装opencv和contrib在ubuntu20.04上非常容易,首先,您需要更新您的系统:sudo apt-get update,然后安装opencv和contrib:sudo apt-get install libopencv-dev python-opencv。您也可以从源代码安装opencv和contrib:git clone https://github.com/opencv/opencv.git。
### 回答2:
在Ubuntu 20.04上安装OpenCV和Contrib模块可以按照以下步骤进行:
1. 打开终端窗口,并通过以下命令更新系统软件包列表:
```shell
sudo apt update
```
2. 安装OpenCV的依赖项,包括构建工具、图像和视频处理库等:
```shell
sudo apt install build-essential cmake git libgtk2.0-dev pkg-config libavcodec-dev libavformat-dev libswscale-dev
sudo apt install libtbb2 libtbb-dev libjpeg-dev libpng-dev libtiff-dev libdc1394-22-dev libv4l-dev libxvidcore-dev libx264-dev
```
3. 通过以下命令从GitHub上获取OpenCV源代码:
```shell
cd ~
git clone https://github.com/opencv/opencv.git
```
4. 进入opencv目录,并创建一个用于构建的子目录:
```shell
cd opencv
mkdir build
cd build
```
5. 在构建目录中,运行以下cmake命令以准备OpenCV的构建过程:
```shell
cmake -D CMAKE_BUILD_TYPE=RELEASE -D CMAKE_INSTALL_PREFIX=/usr/local ..
```
6. 运行以下命令编译OpenCV:
```shell
make -j$(nproc)
```
7. 安装OpenCV到系统:
```shell
sudo make install
```
8. 接下来,我们要安装OpenCV的Contrib模块。首先,返回到OpenCV源代码的根目录:
```shell
cd ../..
```
9. 然后,克隆OpenCV Contrib模块的源代码:
```shell
git clone https://github.com/opencv/opencv_contrib.git
```
10. 进入opencv_contrib目录,并创建一个用于构建的子目录:
```shell
cd opencv_contrib
mkdir build
cd build
```
11. 在构建目录中,运行以下cmake命令以准备OpenCV Contrib的构建过程:
```shell
cmake -D CMAKE_BUILD_TYPE=RELEASE -D CMAKE_INSTALL_PREFIX=/usr/local ../..
```
12. 编译OpenCV Contrib:
```shell
make -j$(nproc)
```
13. 最后,将OpenCV Contrib安装到系统:
```shell
sudo make install
```
完成上述步骤后,您应该成功在Ubuntu 20.04上安装了OpenCV和Contrib模块。
### 回答3:
要在Ubuntu 20.04上安装OpenCV和Contrib模块,你可以按照以下步骤进行操作:
1. 更新系统:打开终端,并使用以下命令更新系统软件包:
```
sudo apt update
sudo apt upgrade
```
2. 安装依赖项:在终端中运行以下命令以安装OpenCV所需的依赖项:
```
sudo apt install build-essential cmake git libgtk2.0-dev pkg-config libavcodec-dev libavformat-dev libswscale-dev
sudo apt install libtbb2 libtbb-dev libjpeg-dev libpng-dev libtiff-dev libdc1394-22-dev libv4l-dev libxvidcore-dev libx264-dev
sudo apt install libatlas-base-dev gfortran python3-dev python3-numpy libgtk-3-dev libcanberra-gtk3-module
```
3. 克隆OpenCV存储库:使用以下命令在你选择的目录中克隆OpenCV库:
```
git clone https://github.com/opencv/opencv.git
cd opencv
git checkout 4.5.0
```
4. 克隆OpenCV Contrib存储库:使用以下命令在同一目录中克隆OpenCV Contrib库:
```
git clone https://github.com/opencv/opencv_contrib.git
cd opencv_contrib
git checkout 4.5.0
```
5. 构建并安装OpenCV:进入OpenCV源代码目录,创建一个新的目录用于构建,然后运行cmake命令以生成构建文件:
```
cd ../opencv
mkdir build
cd build
cmake -D CMAKE_BUILD_TYPE=RELEASE -D CMAKE_INSTALL_PREFIX=/usr/local -D OPENCV_EXTRA_MODULES_PATH=../../opencv_contrib/modules ..
```
6. 构建和安装OpenCV:运行以下命令以进行构建和安装:
```
make -j4 # 使用多线程构建
sudo make install
sudo ldconfig
```
完成上述步骤后,OpenCV和Contrib模块将被成功安装在你的Ubuntu 20.04系统上。你可以使用相应的代码和教程来验证安装并开始使用OpenCV。
阅读全文