views:

49

answers:

1

I am writing a webserver which receives an image and do some processing and replys with results.

The image is in the png format. It is received as a byte[] via POST using PHP. I have to convert this byte[] to OpenCV IplImage format. What are the steps I should follow to get this done?

The way I am currently doing it is reading the image and saving it on the hard drive and parse the file path to OpenCV cvLoadImage() function. I believe doing the way described in the above paragraph is much efficiant than this.

Or is there a way to parse the byte[] directly to some OpenCV function without trying to convert it to IplImage format myself?

Thank you..

+1  A: 

I believe that is not possible.

The bytes you get from the POST request are the actual bytes stored in the file. Because PNG is a compressed format, these bytes need to be decompressed first. (IplImage stores uncompressed bytes of the image)

You could write PNG decompression routines yourself or use some library (check libpng).

Once you have the decompressed bytes, you'll need to setup the IplImage structure.

use cvCreateImageHeader to create an image of the appropriate size and depth, and set the image->data pointer to the decompressed data.

Make sure the decompressed data is in BGR format... interleaved (one blue byte, one green byte, one red byte, and so on).

Utkarsh Sinha