【发布时间】:2018-05-25 14:41:53
【问题描述】:
我无法将图像从网络更改为数组。
谁能帮忙?
非常感谢。
from PIL import Image
from io import BytesIO
import requests
import numpy as np
url =r'https://drive.google.com/uc?id=1xrKyFZAIIR_XVhlhYGHlfLvIr5vQ5EnW'
img = Image.open(BytesIO(requests.get(url).content))
arr = np.array(img, dtype = np.uint8)
Traceback (most recent call last):
File "<pyshell#78>", line 1, in <module>
arr = np.array(img, dtype = np.uint8)
TypeError: int() argument must be a string, a bytes-like object or a number, not 'JpegImageFile'
【问题讨论】:
-
下载图片并保存为.jpg格式。尝试 Scipy 库中的“imread”命令。
-
你有错误吗?哪一个 ?我猜这取决于图像格式
-
这真的很奇怪......第一次调用
np.array(img, dtype = np.uint8)会抛出一个ValueError,但如果你再试一次它就可以了...... -
您要将图像文件的原始字节,还是解码后的图像数据(RGB 值)转换为数组?
-
让@zindarod 帮助...stackoverflow.com/a/50530022/2836621