蘭雅sRGB 个人笔记 https://262235.xyz
提供编程和电脑应用视频教程,工具和源代码
C, C++, Python Programming, Source Code, Video

旧Hexo博客 | Github | IP定位WebAPI | Docker Hub
编程中文文档 | 网盘分享 | 中文Linux命令

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
本原创文章自由转载,转载请注明本博来源及网址 | 当前页面:蘭雅sRGB 个人笔记 » WINDOWS 11 系统 Python 3.10 安装 OpenCV