如何在Ubuntu 18.04上成功安装OpenCV 4.1.1
时间: 2024-06-08 12:12:13 浏览: 179
以下是在Ubuntu 18.04上安装OpenCV 4.1.1的步骤:
1. 更新Ubuntu软件包列表:
```
sudo apt-get update
```
2. 安装OpenCV所需的依赖项:
```
sudo apt-get install build-essential cmake git libgtk2.0-dev pkg-config libavcodec-dev libavformat-dev libswscale-dev
```
3. 安装OpenCV所需的图像I/O库和依赖项:
```
sudo apt-get install libjpeg-dev libpng-dev libtiff-dev libdc1394-22-dev libeigen3-dev libtheora-dev libvorbis-dev libxvidcore-dev libx264-dev libgtk-3-dev libatlas-base-dev gfortran
```
4. 下载OpenCV 4.1.1源代码:
```
wget -O opencv.zip https://github.com/opencv/opencv/archive/4.1.1.zip
```
5. 解压缩下载的文件:
```
unzip opencv.zip
```
6. 创建一个用于编译OpenCV的目录:
```
mkdir opencv-4.1.1/build
cd opencv-4.1.1/build
```
7. 运行CMake来配置编译:
```
cmake -D CMAKE_BUILD_TYPE=RELEASE -D CMAKE_INSTALL_PREFIX=/usr/local ..
```
8. 编译OpenCV:
```
make -j$(nproc)
```
9. 安装OpenCV:
```
sudo make install
```
10. 验证安装是否成功:
```
pkg-config --modversion opencv
```
如果成功安装,将会输出OpenCV版本号。
现在你已经成功地在Ubuntu 18.04上安装了OpenCV 4.1.1。
阅读全文