c++opencvblobiplimage

Opencv : Conversion Mat to IplImage for cvLabel


I have:

Mat *depthImage = new Mat(480, 640, CV_8UC1, Scalar::all(0));

And further in my code I do:

Mat image = *depthImage;

I do some OpenCV stuff with it and then I want to use cvBlob (so blob analysis). Though this function still uses IplImage and not Mat. So I wanted to convert them. I've read that I could just do this:

 IplImage *blobimg = image;

But it doesn't work, I get this error:

Semantic Issue: No viable conversion from 'cv::Mat' to 'IplImage *' (aka '_IplImage *')

Eventually I want to be able to use this function on the newley created IplImage

cvLabel(<#const IplImage *img#>, <#IplImage *imgOut#>, <#CvBlobs &blobs#>)

As you can see the conversion from Mat to IplImage is required. But it is not working. My question is how do I fix this?

Thanks in advance


Solution

  • As Martin Beckett says in the comments, the cheatsheet shows this solution. There is no conversion from cv::Mat to IplImage *, but there is a conversion from cv::Mat to IplImage.

    Change the line

    IplImage *blobimg = image;
    

    to

    IplImage blobimg = image;
    

    and it should compile.

    When calling cvLabel, pass the parameter like

    cvLabel(&blobimg, ...);