我无法将图像从网络更改为数组。
有人可以帮忙吗?
非常感谢。
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'
答案 0 :(得分:0)
感谢Mark的帮助。这个问题的解决方案是:
import cv2
import requests
import numpy as np
url =r'https://drive.google.com/uc?id=1xrKyFZAIIR_XVhlhYGHlfLvIr5vQ5EnW'
resp = requests.get(url).content
image = np.asarray(bytearray(resp), dtype="uint8")
arr = cv2.imdecode(image, cv2.IMREAD_COLOR)