- 查看是否有opencv
打开python直接引用下
import cv2
cds@cds-virtual-machine:~$ python
Python 3.5.2 (default, Oct 8 2019, 13:06:37)
[GCC 5.4.0 20160609] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import cv2
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: No module named 'cv2'
>>>
- 安装opencv
通过命令行输入以下指令安装
pip install opencv-python
cds@cds-virtual-machine:~$ pip install opencv-python
Collecting opencv-python
Downloading https://mirrors.aliyun.com/pypi/packages/00/aa/5880b514dff3642161bda4af39aa2a544cb5949d9e194d1ef81e06fcc2f2/opencv_python-4.2.0.34-cp35-cp35m-manylinux1_x86_64.whl (28.2MB)
100% |████████████████████████████████| 28.2MB 50kB/s
Collecting numpy>=1.11.1 (from opencv-python)
Downloading https://mirrors.aliyun.com/pypi/packages/45/25/48e4ea892e93348d48a3a0d23ad94b176d6ab66084efcd881c78771d4abf/numpy-1.18.3-cp35-cp35m-manylinux1_x86_64.whl (20.0MB)
100% |████████████████████████████████| 20.0MB 71kB/s
Installing collected packages: numpy, opencv-python
Successfully installed numpy-1.18.2 opencv-python
- 查看安装好了以及安装版本
打开python,然后导入cv2,再接着打印版本号。
cds@cds-virtual-machine:~$ python
Python 3.5.2 (default, Oct 8 2019, 13:06:37)
[GCC 5.4.0 20160609] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import cv2
>>> print(cv2.__version__)
4.2.0
>>>
- 扩展包(可不安装)
pip install opencv-contrib-python