![](https://secure.gravatar.com/avatar/20ecc2648c30f3c3c5a37804709da79f.jpg?s=120&d=mm&r=g)
I was trying to figure out last night how to get libjpeg to decode a jpeg which existed in memory, and write the decoded image to a memory buffer. I failed. The use case is this: I connect to a wireless video camera and make requests for image via HTTP GET. The image is sent in jpeg format as a stream of bytes which gets stored in a python buffer object. I need to convert this jpeg to an RGB numpy array. This turned out to be trivial to do with PIL and its file parser that accepts a stream of bytes. in essence: In [1]: import httplib In [2]: from PIL import ImageFile In [3]: import numpy as np In [4]: conn = httplib.HTTPConnection('www.therealstevencolbert.com') In [5]: conn.request('GET', '/dump/IMG_0408_rs.JPG') In [6]: r1 = conn.getresponse() In [7]: r1.status Out[7]: 200 In [8]: data = r1.read() In [9]: parser = ImageFile.Parser() In [10]: parser.feed(data) In [11]: img = parser.close() In [12]: img.show() In [13]: numpyimg = np.asarray(img) In [14]: numpyimg.shape Out[14]: (768, 1024, 3) In [15]: numpyimg.dtype Out[15]: dtype('uint8') This is incredibly valuable and I think we should consider adding such capability to scikits image. I'd even be willing to work on this after I'm done with the opencv stuff. Cheers! Chris