Code Yarns ‍👨‍💻
Tech BlogPersonal Blog

OpenCV error constructing Mat from IplImage

📅 2013-Jul-04 ⬩ ✍️ Ashwin Nanjappa ⬩ 🏷️ error, iplimage, mat, opencv ⬩ 📚 Archive

Problem

Tried to compile some code that uses OpenCV and got this error:

foo.cpp:268:27: error: no matching function for call to ‘cv::Mat::Mat(IplImage*&)’

The code at that error line tries to construct a cv::Mat object from IplImage:

void boohoo(IplImage* i)
{
    // ...
    abracadabra(cv::Mat(i));
    // ...
}

Solution

It turns out this code worked in older versions of OpenCV. But with recent versions of OpenCV, this cv::Mat constructor is no longer present.

Instead, the conversion has to be performed using a cv::cvarrToMat function:

void boohoo(IplImage* i)
{
    // ...
    abracadabra(cv::cvarrToMat(i));
    // ...
}

Tried with: OpenCV 2.4.9 and Ubuntu 12.04 LTS


© 2022 Ashwin Nanjappa • All writing under CC BY-SA license • 🐘 @codeyarns@hachyderm.io📧