Friday, May 22, 2015

OpenCV error constructing Mat from IplImage

Problem
Tried to compile some code that uses OpenCV and got this error:
1
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:
1
2
3
4
5
6
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:
1
2
3
4
5
6
void boohoo(IplImage* i)
{
    // ...
    abracadabra(cv::cvarrToMat(i));
    // ...
}
Tried with: OpenCV 2.4.9 and Ubuntu 12.04 LTS

No comments:

Post a Comment