0

I cannot change an image from web to an array.

Can anyone help?

Thank you very much.

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'
mkrieger1
  • 19,194
  • 5
  • 54
  • 65
John
  • 691
  • 1
  • 7
  • 20

1 Answers1

0

Thank you for the help of Mark. The solution to this problem is:

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)
John
  • 691
  • 1
  • 7
  • 20