Mat轉換成IplImage型別
阿新 • • 發佈:2019-01-03
Mat 類有一個IplImage()運算子成員函式:
class CV_EXPORT Mat
{
// ...
//! converts header to IplImage; no data is copied
operator IplImage() const;
//...
};
利用該成員函式可以實現Mat類向IplImage類的轉換,呼叫方法如下:
(1)和(2)都會呼叫Mat類的operator IplImage()成員函式,實現向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; }