Mat转换成IplImage类型

来源:互联网 发布:局域网语音通话软件 编辑:程序博客网 时间:2024/05/17 21:54

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;}


(1)和(2)都会调用Mat类的operator IplImage()成员函数,实现向IplImage类的转换

2 1