【问题标题】:Convert image loaded as binary string into numpy array将加载为二进制字符串的图像转换为 numpy 数组
【发布时间】:2018-11-22 02:04:07
【问题描述】:

有没有一种方法可以将加载为二进制字符串的图像转换为大小为 (im_height, im_width, 3) 的 numpy 数组?像这样的:

# read image as binary string
with open(img_path, "rb") as image_file:
  image_string = image_file.read()

# convert image string to numpy
image_np = convert_binary_string_to_numpy(image_string)

这个转换函数是什么样子的?我正在使用解密,因此我需要使用二进制字符串。 谢谢!

【问题讨论】:

标签: python numpy opencv pillow rncryptor


【解决方案1】:
import io
import numpy as np    
from PIL import Image

image_string = open(IMG_PATH, 'rb').read()
img = Image.open(io.BytesIO(image_string))
arr = np.asarray(img)

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-04-25
    • 2020-07-12
    • 2013-02-11
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多