imageio 载入 Buffer 格式的图片

Posted q735613050

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了imageio 载入 Buffer 格式的图片相关的知识,希望对你有一定的参考价值。

import zipfile
import imageio
import cv2

# 载入压缩文件
Z = zipfile.ZipFile(path)
# 载入 buffer
buffer = Z.read(name)

使用 OpenCV 3

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)

以上是关于imageio 载入 Buffer 格式的图片的主要内容,如果未能解决你的问题,请参考以下文章