我无法将图像从网络更改为数组。
任何人都可以帮忙吗?
非常感谢你。
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'
感谢马克的帮助。这个问题的解决方法是:
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)
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句