ubuntu18.04安装opencv
时间: 2023-05-01 18:00:36 浏览: 154
在 Ubuntu 18.04 上安装 OpenCV 的过程如下:
1. 更新系统并安装依赖项:
```
sudo apt update
sudo apt upgrade
sudo apt install build-essential cmake git pkg-config libgtk-3-dev
sudo apt install libavcodec-dev libavformat-dev libswscale-dev libv4l-dev
sudo apt install libxvidcore-dev libx264-dev
sudo apt install libjpeg-dev libpng-dev libtiff-dev gfortran openexr
sudo apt install libatlas-base-dev python3-dev python3-numpy
```
2. 下载 OpenCV 源码:
```
git clone https://github.com/opencv/opencv.git
git clone https://github.com/opencv/opencv_contrib.git
```
3. 编译并安装 OpenCV:
```
cd opencv
mkdir build
cd build
cmake -D CMAKE_BUILD_TYPE=RELEASE \
-D CMAKE_INSTALL_PREFIX=/usr/local \
-D INSTALL_C_EXAMPLES=ON \
-D INSTALL_PYTHON_EXAMPLES=ON \
-D OPENCV_GENERATE_PKGCONFIG=ON \
-D OPENCV_EXTRA_MODULES_PATH=../../opencv_contrib/modules \
-D BUILD_EXAMPLES=ON ..
```
然后执行
```
make -j4
sudo make install
sudo ldconfig
```
完成后,您可以使用 Python 或 C++ 来使用 OpenCV。请注意,编译和安装 OpenCV 可能需要较长时间,并占用较大空间。
阅读全文