I have following function. I want to copy back some data from Mat to
IplImage * type and return it to the main control.
This is silly, but I couldn’t find a proper way to do this! The cheat
sheet havent say anything about Mat->IplImage * conversion WITH data
copy (since I need it outside the function).
Any idea or pointer is appreciated.
Best
–Ali
int test(IplImage **srcImage, int num_images)
{
vector<Mat> images(num_images);
for (int i = 0; i < num_images; ++i)
{
images[i] = Mat(srcImage[i]); // I guess should be correct!
....
// some manipulations on images[i]
}
// this should be wrong!
for (int i = 0; i < num_images; ++i)
{
cvReleaseImage(&srcImage[i]);
srcImage[i] = new IplImage(images[i]);
images[i].clear();
}
return 0;
}
Short version: Convert to a temporary
IplImage, then usecvCopy.However, there are several issues with your code:
so far, yes.
If the manipulations are in-place (don’t reallocate the
Mats), you don’t need to copy the data back, since theMatconstructor didn’t copy the data in the first place. If you do reallocate, then …This can be problematic.
images[i]might still be using the same memory.new IplImageisn’t going to do you any good. It doesn’t have meaningful constructors, usecvCreateImage.This is not neccessary, as the vector goes out of scope anyway.
The last loop should look something like this: