ubuntu18.04安装openCV
时间: 2023-11-02 22:52:24 浏览: 164
ubuntu opencv安装
3星 · 编辑精心推荐
安装OpenCV可以按照以下步骤进行:
1. 更新系统:
```
sudo apt update
sudo apt upgrade
```
2. 安装必要的依赖项:
```
sudo apt install build-essential cmake git libgtk2.0-dev pkg-config libavcodec-dev libavformat-dev libswscale-dev
sudo apt install python3-dev python3-numpy libtbb2 libtbb-dev libjpeg-dev libpng-dev libtiff-dev libdc1394-22-dev
```
3. 下载OpenCV源码:
```
cd ~
git clone https://github.com/opencv/opencv.git
cd opencv
git checkout <opencv_version> # 替换<opencv_version>为你想要安装的OpenCV版本,例如4.5.2
```
4. 创建并进入构建目录:
```
cd ~
mkdir build_opencv
cd build_opencv
```
5. 配置编译参数:
```
cmake ../opencv
```
6. 编译并安装OpenCV:
```
make -j$(nproc)
sudo make install
```
7. 配置动态链接库路径:
```
sudo /bin/bash -c 'echo "/usr/local/lib" > /etc/ld.so.conf.d/opencv.conf'
sudo ldconfig
```
安装完成后,你可以在Python中导入OpenCV进行使用。例如,运行以下代码验证OpenCV是否安装成功:
```python
import cv2
print(cv2.__version__)
```
这将打印出安装的OpenCV版本号。
阅读全文