user
user

Reputation: 101

Reading image from url takes too long

Here’s the code I used:

import requests
from PIL import Image
import io
import cv2
response = requests.get(df1.URL[0]).content

im = Image.open(io.BytesIO(response))

The image is very large. Is there a way to fasten things? EDIT: I don't want to save image on disk. I just want to read it on the fly.

Upvotes: 0

Views: 422

Answers (2)

user
user

Reputation: 101

Thank you @αԋɱҽԃαмєяιcαη for your help. I made a comparison between duration of loading for different methods. Here's a link to see results comparison

Upvotes: 0

Well, to have this question clear as for now. Could you please check the timing between your code and the code below on a single image. and let us know the difference.

In case if you looking to deal with multiple images, so you need threading etc.. concurrent.futures

import requests

r = requests.get(url)

with open("out.jpg", 'wb') as f:
    f.write(r.content)

also kindly set stream=True and give it a try

import requests
from PIL import Image
import io
import cv2
response = requests.get(df1.URL[0],stream=True).content

im = Image.open(io.BytesIO(response))

Upvotes: 2

Related Questions