Read image directly from buffer

classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

Read image directly from buffer

Ish Rishabh
Hi,

I am writing an application in which I am reading a JPEG image through http from a camera. So I have the compressed image data in buffer. I want to extract image in IplImage format from this buffer, without writing the buffer onto the disk as JPEG file. cvLoadImage() reads only from the disk and so I cannot use it.

Is there a way I can directly access IplImage from the jpeg buffer? The buffer is UCHAR.

Any help will be appreciated.

Thanks,
Ish



     
Reply | Threaded
Open this post in threaded view
|

Re: Read image directly from buffer

Gabriele-2

> Is there a way I can directly access IplImage from the jpeg buffer?
The buffer is UCHAR.

I guess you can just go through the image in the buffer and copy the
single pixel values on the IplImage object that you'll have previously
created.

Reply | Threaded
Open this post in threaded view
|

Re: Read image directly from buffer

Xavier Delacour
In reply to this post by Ish Rishabh
On Tue, Jan 13, 2009 at 6:45 PM, Ish Rishabh <[hidden email]> wrote:

> Hi,
>
> I am writing an application in which I am reading a JPEG image through http
> from a camera. So I have the compressed image data in buffer. I want to
> extract image in IplImage format from this buffer, without writing the
> buffer onto the disk as JPEG file. cvLoadImage() reads only from the disk
> and so I cannot use it.
>
> Is there a way I can directly access IplImage from the jpeg buffer? The
> buffer is UCHAR.

No, the image decompress routines only read from files. The underlying
libraries I'm sure support decoding directly from memory, so maybe you
could patch opencv to support it. Otherwise you're only choices I
think are writing/reading temp files and using libjpg or something
outside of opencv.

Xavier

>
> Any help will be appreciated.
>
> Thanks,
> Ish
>
>
Reply | Threaded
Open this post in threaded view
|

Re: Read image directly from buffer

Gabriele-2

> No, the image decompress routines only read from files.

Ops, I missed the fact that the image was still compressed. Please
ignore my post.


Reply | Threaded
Open this post in threaded view
|

Re: Read image directly from buffer

jaybromley
In reply to this post by Xavier Delacour
--- In [hidden email], "Xavier Delacour" <xavier.delacour@...>
wrote:
>
> On Tue, Jan 13, 2009 at 6:45 PM, Ish Rishabh <ish_rishabh@...> wrote:
> > Hi,
> >
> > I am writing an application in which I am reading a JPEG image
through http
> > from a camera. So I have the compressed image data in buffer. I
want to
> > extract image in IplImage format from this buffer, without writing the
> > buffer onto the disk as JPEG file. cvLoadImage() reads only from
the disk
> > and so I cannot use it.
> >
> > Is there a way I can directly access IplImage from the jpeg
buffer? The
> > buffer is UCHAR.

You will have to use some library to decompress the JPEG image into an
uncompressed format (e.g. bitmap) that OpenCV can handle. Create a
header for the image and then use cvSetData to point the image header
to the decoded image buffer. For image transcoding I recommend Jasper
(http://www.ece.uvic.ca/~mdadams/jasper/).

Regards,
Jay