I am trying to open a large list of images using OpenCV on python, because I need to work with them latter.
Actually, I can achieve this goal with pillow like this:
url = r'https://i.imgur.com/DrjBucJ.png'
response = requests.get(url, stream=True).raw
guess = Image.open(response).resize(size)
I am using the library requests from python.
The response looks like this: b'\x89PNG\r\n\x1a\n\x00\x00\x00\rIHDR\x00\x00\x01\xdb\...
And if I am not wrong, those are the values of the pixels from the image of the url, correct?
My question is: how can I do the same with OpenCV?
I have tried it like:
resp = requests.get(url)
image = np.asarray(bytearray(resp.read()), dtype="uint8")
image = cv2.imdecode(image, cv2.IMREAD_COLOR)
And I get this error:
image = np.asarray(bytearray(resp.read()), dtype="uint8")
AttributeError: 'Response' object has no attribute 'read'
I got the code from this web: https://www.pyimagesearch.com/2015/03/02/convert-url-to-image-with-python-and-opencv/
urllibdiffers fromrequests, tryresp.raw.