Mat转换成IplImage类型

转自:http://blog.csdn.net/lichengyu/article/details/24272349

Mat 类有一个IplImage()运算符成员函数:

class CV_EXPORT Mat
{
// ...
//! converts header to IplImage; no data is copied
    operator IplImage() const;
//...
};

利用该成员函数可以实现Mat类向IplImage类的转换,调用方法如下:

#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <iostream>

using namespace cv;
using namespace std;

int main( int argc, char** argv )
{
    Mat image = imread("Debug/lena_std.tif", IMREAD_COLOR); // Read the file

    if(! image.data ) // Check for invalid input
    {
        cout << "Could not open or find the image" << std::endl ;
        return -1;
    }


    //convert to IplImage
    IplImage ipl_img(image);  //(1)
    //IplImage ipl_img = image; //(2)
    cvShowImage("ipl_img", &ipl_img);
    cvWaitKey(0);

    return 0;
}


你可能感兴趣的:(Mat转换成IplImage类型)