views:

932

answers:

2

Hi,

i wonder if there is a easy way to convert my float array image to iplimage, which can be handled by opencv. Of course i could create an empty iplimage with the same size and just copy ever pixel from my float array image to the emplty iplimage, but is there more elegant solution to this. Maybe a faster less memory consuming method, since the source images are pretty large and the copy process would take a while.

Best regards,

Zhengtonic

+1  A: 

You can fill an iplimage structure 'by hand' to describe your array following the comments here.

The field imageData will point to your original array.

But then don't use deallocation functions on it. Just delete the structure in the end.

fa.
+2  A: 

You can do something like this (assuming 32 bit floats):

float* my_float_image_data;

CvSize size;
size.height = height ;
size.width = width;
IplImage* ipl_image_p = cvCreateImageHeader(size, IPL_DEPTH_32F, 1);
ipl_image_p->imageData = my_float_image_data;
ipl_image_p->imageDataOrigin = ipl_image_p->imageData;
Dani van der Meer
Thanks pal! This should work out. :)
zhengtonic
The OpenCV documentation says that IplImage->imageData is of type char. In this example its a float array - how does that work. Also, I'm wondering, if the image data is a 2D array or if its flattened into 1D?
freakTheMighty
@freakTheMighty The data is stored in a char array, but every 4 bytes are interpreted as one float. In C that is possible :). See http://www.comp.leeds.ac.uk/vision/opencv/iplimage.html for a good description.
Dani van der Meer