Lors de la gestion des données d'image en Python, elles peuvent être gérées par "numpy (opencv)", "oreiller" et "octet". Un mémorandum pour la conversion de chaque type.
num_bytes = num_numpy.tobytes()
numpy -> pil
num_pil = Image.fromarray(num_numpy)
pil -> bytes
num_byteio = io.BytesIO()
num_byteio.save(num_pil, format='png')#PNG créé temporairement
num_bytes = num_byteio.getvalue()
pil -> numpy
num_numpy = np.asarray(num_pil)
bytes -> numpy
num_byteio = io.BytesIO(num_bytes)
with Image.open(num_byteio) as img
num_numpy = np.asarray(img)
bytes -> pil
num_byteio = io.BytesIO(num_bytes)
num_pil = Image.open(num_byteio)
Recommended Posts