python 中 opencv 的使用为:

import cv2

img_cv2 = cv2.imread('test.jpg')

opencv python 接口的安装有两种方式:

[1] - W1:

Ubuntu - OpenCV 源码安装与测试 - AIUAI

[2] - W2: 直接采用 pip 安装

pip install opencv-python

W2 安装在 import cv2 时出现如下问题及解决:

ImportError: libgthread-2.0.so.0: cannot open shared object file: No such file or directory
ImportError: libSM.so.6: cannot open shared object file: No such file or directory
ImportError: libXrender.so.1: cannot open shared object file: No such file or directory
ImportError: libXext.so.6: cannot open shared object file: No such file or directory

解决方法:

sudo apt-get install libglib2.0-dev
sudo apt-get install libsm6
sudo apt-get install libxrender1
sudo apt-get install libxext-dev

问题2:

ImportError: libGL.so.1: cannot open shared object file: No such file or directory

解决方法:

sudo apt install libgl1-mesa-glx
Last modification:December 13th, 2021 at 03:58 pm