Conversion from IplImage* to cv::MAT

前端 未结 5 355
爱一瞬间的悲伤
爱一瞬间的悲伤 2020-12-04 20:05

I searched to convert an IplImage* to Mat, but all answers were about the conversion to cvMat.

How, can I do it? and what is the difference between Mat and cvMat?

相关标签:
5条回答
  • 2020-12-04 20:24

    here is a good solution

    Mat(const IplImage* img, bool copyData=false);
    
    0 讨论(0)
  • 2020-12-04 20:28
    • cv::Mat or Mat, both are same.

    • Mat has a operator CvMat() so simple assignment works

    Convert Mat to CvMat

    Mat mat = ---------;
    CvMat cvmat = mat;
    

    Convert CVMat to Mat

    Mat dst = Mat(cvmat, true);  
    

    Convert Mat to IplImage*

    > For Single Channel

    IplImage* image = cvCloneImage(&(IplImage)mat); 
    

    > For Three Channel

    IplImage* image = cvCreateImage(cvSize(mat.cols, mat.rows), 8, 3);
    IplImage ipltemp = mat;
    cvCopy(&ipltemp, image);
    

    Hope this helps you. Cheers :)

    0 讨论(0)
  • 2020-12-04 20:29

    Check out the Mat documentation.

    // converts old-style IplImage to the new matrix; the data is not copied by default
    Mat(const IplImage* img, bool copyData=false);
    
    0 讨论(0)
  • 2020-12-04 20:36

    The recommended way is the cv::cvarrToMat function

    cv::Mat - is base data structure for OpenCV 2.x

    CvMat - is old C analog of cv::Mat

    0 讨论(0)
  • 2020-12-04 20:45

    For the records: taking a look at core/src/matrix.cpp it seems that, indeed, the constructor cv::Mat(IplImage*) has disappeared.

    But I found this alternative:

    IplImage * ipl = ...;
    cv::Mat m = cv::cvarrToMat(ipl);  // default additional arguments: don't copy data.
    
    0 讨论(0)
提交回复
热议问题