Ask Your Question
0

cv2.imread a url

asked 2013-07-08 23:21:09 -0600

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")

edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted
1

answered 2013-07-09 01:38:42 -0600

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()
edit flag offensive delete link more

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 ( 2013-07-09 09:24:12 -0600 )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 ( 2013-07-09 09:56:45 -0600 )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 ( 2013-07-09 10:08:09 -0600 )edit
1

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

jayrambhia gravatar imagejayrambhia ( 2013-07-10 04:11:34 -0600 )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 ( 2013-07-10 21:18:12 -0600 )edit
2
jayrambhia gravatar imagejayrambhia ( 2013-07-11 02:02:09 -0600 )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 ( 2013-09-09 15:52:38 -0600 )edit

Question Tools

2 followers

Stats

Asked: 2013-07-08 23:21:09 -0600

Seen: 13,922 times

Last updated: Jul 09 '13