The documentation on this seems incredibly spotty.
I've basically got an empty array of IplImage*s (IplImage** imageArray) and I'm calling a function to import an array of cv::Mats - I want to convert my cv::Mat into an IplImage* so I can copy it into the array.
Currently I'm trying this:
while(loop over cv::Mat array)
{
IplImage* xyz = &(IplImage(array[i]));
cvCopy(iplimagearray[i], xyz);
}
Which generates a segfault.
Also trying:
while(loop over cv::Mat array)
{
IplImage* xyz;
xyz = &array[i];
cvCopy(iplimagearray[i], xyz);
}
Which gives me a compile time error of:
error: cannot convert ‘cv::Mat*’ to ‘IplImage*’ in assignment
Stuck as to how I can go further and would appreciate some advice :)
cv::Mat
is the new type introduce in OpenCV2.X while theIplImage*
is the "legacy" image structure.Although,
cv::Mat
does support the usage ofIplImage
in the constructor parameters, the default library does not provide function for the other way. You will need to extract the image header information manually. (Do remember that you need to allocate the IplImage structure, which is lack in your example).you work with new as an originally declared IplImage*.
Guess this will do the job.
Edit: If you face compilation errors, try this way:
In case of gray image, I am using this function and it works fine! however you must take care about the function features ;)
According to OpenCV cheat-sheet this can be done as follows:
The cv::cvarrToMat function takes care of the conversion issues.
One problem might be: when using external ipl and defining HAVE_IPL in your project, the ctor
found in ../OpenCV/modules/core/src/matrix.cpp is not used/instanciated and conversion fails.
You may reimplement it in a way similar to :