How to convert a Mat variable type in an IplImage variable type in OpenCV 2.0?

前端 未结 4 1750
别跟我提以往
别跟我提以往 2020-12-10 04:22

I am trying to rotate an image in OpenCV.

I\'ve used this code that I found here on Stack Overflow:

Mat source(img);
Point2f src_center(source.cols/2         


        
相关标签:
4条回答
  • 2020-12-10 04:34

    In later versions of OpenCV 2.4 and above, we can convert it simply by

    cv::Mat inMat;
    //do the stuffs
    IplImage* outIPL = (IplImage*)(&IplImage(inMat));
    
    0 讨论(0)
  • 2020-12-10 04:44

    Norman in his blog describes the following (Although it is not 2.0, it should apply to your problem.):

    To transform from CvMat to IplImage, Use function:

    IplImage* cvGetImage( const CvArr* arr, IplImage* image_header );  
    

    The function cvGetImage returns image header for the input array that can be matrix - CvMat*, or image - IplImage*. In the case of image the function simply returns the input pointer. In the case of CvMat* it initializes image_header structure with parameters of the input matrix. Usage:

    IplImage stub, *dst_img;
    dst_img = cvGetImage(src_mat, &stub);
    
    0 讨论(0)
  • 2020-12-10 04:47

    In the new OpenCV 2.0 C++ interface it's not really necessary to change from back and forth between Mat and IplImage, but if you want to you can use the IplImage operator:

    IplImage dst_img = dst;
    

    Note that only the IplImage header is created and the data (pixels) will be shared. For more info see the OpenCV C++ interface or the image.cpp example in the OpenCV-2.0/samples/c directory.

    0 讨论(0)
  • 2020-12-10 04:58

    For having the whole IplImage object, I've used this code:

    Mat matImage;
    IplImage* iplImage;
    
    iplImage = cvCreateImage(cvSize(640,480), IPL_DEPTH_8U, 1);
    iplImage->imageData = (char *) matImage.data;
    

    You can also copy the data instead of pointer:

    memcpy(iplImage->imageData, matimage.data, 640*480);
    
    0 讨论(0)
提交回复
热议问题