题注:OpenCV 使用 pip install -U opencv-python 即可安装。

import zipfile
import imageio
import cv2

# 载入压缩文件
Z = zipfile.ZipFile(path)
# 载入 buffer
buffer = Z.read(name)
img1 = np.frombuffer(buffer, np.uint8)
# 解码为 np.uint8
img_cv = cv2.imdecode(img1, cv2.IMREAD_ANYCOLOR)
# BGR 或 GRAY 转换为 RGB
img = cv2.cvtColor(img_cv, cv2.COLOR_GRAY2RGB)

下面使用一种简便方式:

使用 imageio

img = imageio.imread(buffer)

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-08-28
  • 2022-12-23
  • 2021-12-04
  • 2021-10-10
猜你喜欢
  • 2022-12-23
  • 2021-04-03
  • 2022-12-23
  • 2021-08-20
  • 2021-05-30
  • 2022-12-23
  • 2021-11-17
相关资源
相似解决方案