Converting cv::Mat to IplImage*

前端 未结 8 1130
庸人自扰
庸人自扰 2020-11-28 22:51

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

8条回答
  •  伪装坚强ぢ
    2020-11-28 23:19

    One problem might be: when using external ipl and defining HAVE_IPL in your project, the ctor

    _IplImage::_IplImage(const cv::Mat& m)
    {
        CV_Assert( m.dims <= 2 );
        cvInitImageHeader(this, m.size(), cvIplDepth(m.flags), m.channels());
        cvSetData(this, m.data, (int)m.step[0]);
    }
    

    found in ../OpenCV/modules/core/src/matrix.cpp is not used/instanciated and conversion fails.

    You may reimplement it in a way similar to :

    IplImage& FromMat(IplImage& img, const cv::Mat& m)
    {
        CV_Assert(m.dims <= 2);
        cvInitImageHeader(&img, m.size(), cvIplDepth(m.flags), m.channels());
        cvSetData(&img, m.data, (int)m.step[0]);
        return img;
    }
    
    IplImage img;
    FromMat(img,myMat);
    

提交回复
热议问题