WINDOWS 11 系统 Python 3.10 安装 OpenCV

opencv.webp

1. 先安装 NumPy 库,使用 OpenCV 需要依赖 NumPy 这个库

python -m pip install numpy

Collecting numpy
  Using cached numpy-1.23.1-cp38-cp38-win_amd64.whl (14.7 MB)
Installing collected packages: numpy
Successfully installed numpy-1.23.1

2. pip 安装 OpenCV 库的名称是 opencv-python,所以下面命令错误

python -m pip install opencv
ERROR: Could not find a version that satisfies the requirement opencv (from versions: none)
ERROR: No matching distribution found for opencv

3. pip 安装 OpenCV 库的名称是 opencv-python

python -m pip install opencv-python

Collecting opencv-python
  Downloading opencv_python-4.6.0.66-cp36-abi3-win_amd64.whl (35.6 MB)
     ---------------------------------------- 35.6/35.6 MB 599.9 kB/s eta 0:00:00
Requirement already satisfied: numpy>=1.17.3 in c:\users\vip\appdata\local\programs\python\python38\lib\site-packages (from opencv-python) (1.23.1)
Installing collected packages: opencv-python
Successfully installed opencv-python-4.6.0.66

4. 使用 OpenCV 库转换图片格式示例:把png格式转换jpg和webp格式

import cv2
img = cv2.imread('test.png')
cv2.imwrite('test.jpg', img)
cv2.imwrite('test.webp', img)

Linux 系统安装 OpenCV 库, 安装的时候会自动安装依赖库 numpy

pip3.png

python3 -m pip install –upgrade pip # 先更新pip

pip3 install opencv-python

Collecting opencv-python
  Downloading opencv_python-4.6.0.66-cp36-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (60.9 MB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 60.9/60.9 MB 10.1 MB/s eta 0:00:00
Collecting numpy>=1.17.3
  Downloading numpy-1.23.1-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (17.1 MB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 17.1/17.1 MB 15.0 MB/s eta 0:00:00
Installing collected packages: numpy, opencv-python
Successfully installed numpy-1.23.1 opencv-python-4.6.0.66
© 版权声明
THE END
喜欢就支持一下吧
点赞0
分享
评论 抢沙发

请登录后发表评论