How to load a png image received through http post to OpenCV IplImage format
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开发者_如何学C 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..
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).
精彩评论