将 cv::Mat 转换为 IplImage*

2021-12-10 00:00:00 opencv c++

关于此的文档似乎非常参差不齐.

The documentation on this seems incredibly spotty.

我基本上有一个 IplImage*s (IplImage** imageArray) 的空数组,我正在调用一个函数来导入一个 cv::Mats 数组 - 我想将我的 cv::Mat 转换为 IplImage* 这样我就可以将其复制到数组中.

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.

目前我正在尝试这个:

while(loop over cv::Mat array)
{
    IplImage* xyz = &(IplImage(array[i]));
    cvCopy(iplimagearray[i], xyz);
}

产生段错误.

也在尝试:

while(loop over cv::Mat array)
{
    IplImage* xyz;
    xyz = &array[i];
    cvCopy(iplimagearray[i], xyz);
}

这给了我一个编译时错误:错误:无法在赋值中将‘cv::Mat*’转换为‘IplImage*’

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 是 OpenCV2.X 中引入的新类型,而 IplImage* 是遗留"图像结构.

cv::Mat is the new type introduce in OpenCV2.X while the IplImage* is the "legacy" image structure.

虽然cv::Mat确实支持在构造函数参数中使用IplImage,但默认库不提供其他方式的功能.您将需要手动提取图像标题信息.(请记住,您需要分配 IplImage 结构,这在您的示例中是缺失的).

Although, cv::Mat does support the usage of IplImage 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).

相关文章