Ubuntu18.04安装opencv
时间: 2023-03-01 18:01:16 浏览: 108
你可以通过以下步骤在 Ubuntu 18.04 上安装 OpenCV:
1. 更新系统软件包:打开终端并输入以下命令:
```
sudo apt-get update
```
2. 安装 OpenCV 所需的依赖项:
```
sudo apt-get install build-essential cmake git pkg-config
sudo apt-get install libjpeg-dev libtiff5-dev libjasper-dev libpng-dev
sudo apt-get install libavcodec-dev libavformat-dev libswscale-dev libv4l-dev
sudo apt-get install libxvidcore-dev libx264-dev
sudo apt-get install libgtk-3-dev
sudo apt-get install libhdf5-dev
sudo apt-get install python3-dev python3-numpy
```
3. 下载 OpenCV 源代码:
```
git clone https://github.com/opencv/opencv.git
```
4. 进入 OpenCV 目录:
```
cd opencv
```
5. 创建并进入 build 目录:
```
mkdir build
cd build
```
6. 使用 CMake 生成 Makefile:
```
cmake -D CMAKE_BUILD_TYPE=RELEASE \
-D CMAKE_INSTALL_PREFIX=/usr/local \
-D BUILD_opencv_python3=ON \
-D BUILD_EXAMPLES=OFF ..
```
7. 编译并安装 OpenCV:
```
make -j4
sudo make install
```
8. 配置动态链接库路径:
```
sudo sh -c 'echo "/usr/local/lib" >> /etc/ld.so.conf.d/opencv.conf'
sudo ldconfig
```
现在,您已经成功地在 Ubuntu 18.04 上安装了 OpenCV。
阅读全文