Ask Your Question
0

cv2.imread a url

asked Jul 9 '13

smhall05 gravatar image

How can I read an image from a url with cv2.imread? I am able to do it with SimpleCV, but it is rather bulky just to do an image read.

I would like to achieve something like:

im = cv2.imread("http://example.com/someimage.jpg")

Preview: (hide)

1 answer

Sort by » oldest newest most voted
1

answered Jul 9 '13

berak gravatar image

imread can't read from urls, but videocapture can !

cap = cv2.VideoCapture("http://example.com/someimage.jpg")
if( cap.isOpened() ) :
    ret,img = cap.read()
    cv2.imshow("win",img)
    cv2.waitKey()
Preview: (hide)

Comments

1

Thanks that works, but it is slower than using:

from SimpleCV import Image img = Image("http://example.com/someimage.jpg")

For one thing I am getting the below warnings:

Using network protocols without global network initialization. Please use avformat_network_init(), this will become mandatory later.

Looking it up now, thought I'd post here in parallel.

smhall05 gravatar imagesmhall05 (Jul 9 '13)edit

hhm, do you know, what the simplecv ppl are doing there ?

loading the img via urlrequest or such, and then imdecode() that buffer might be much faster indeed

berak gravatar imageberak (Jul 9 '13)edit

Actually I forgot to comment out the from SimpleCV import Image line. When I did that, the speeds are comparable. If I already have the image local and use cv2.imread, I get 200ms back when processing the image. My goal is to get pretty close to that.

Not sure what they are doing, guess I have some homework!

smhall05 gravatar imagesmhall05 (Jul 9 '13)edit
1

SimpleCV uses urllib2.Request to fetch the data, and uses StringIO and PIL to convert image.

jayrambhia gravatar imagejayrambhia (Jul 10 '13)edit

Can you provide an example of how it is done? Maybe I can utilize that snippet of code instead of importing SimpleCV.

smhall05 gravatar imagesmhall05 (Jul 11 '13)edit
2
jayrambhia gravatar imagejayrambhia (Jul 11 '13)edit

@berak@jayrambhia Using network protocols without global network initialization. Please use avformat_network_init(), this will become mandatory later.

The code that is triggering this is below. If I pass in a local jpeg it is clean, when I pas in a url of the jpeg, I get the above.

link = sys.argv[1] cap = cv2.VideoCapture(link) if( cap.isOpened() ): ret, im = cap.read()

Any ideas how to clean this up?

smhall05 gravatar imagesmhall05 (Sep 9 '13)edit

Question Tools

2 followers

Stats

Asked: Jul 9 '13

Seen: 14,222 times

Last updated: Jul 09 '13