Ask Your Question

Revision history [back]

How to create CVImageBufferRef from cv:Mat

Hi,

I'm using OpenCV on iOS and trying to stream video after modifying original video.

I could find out many articles that explains how to create cv:Mat from CVImageBufferRef.

like CVImageBufferRef imageBuffer = CMSampleBufferGetImageBuffer(sampleBuffer);

    /*Lock the image buffer*/
    CVPixelBufferLockBaseAddress(imageBuffer,0);

    /*Get information about the image*/
    uint8_t *baseAddress = (uint8_t *)CVPixelBufferGetBaseAddress(imageBuffer);
    size_t width = CVPixelBufferGetWidth(imageBuffer);
    size_t height = CVPixelBufferGetHeight(imageBuffer);

    cv::Mat frame(height, width, CV_8UC4, (void*)baseAddress);

But how can I reverse it? I could not find articles to convert cv:Mat to CVImageBufferRef.

Since C++ is not familiar to me, it might be too easy. Could someone give me hist or piece of code? Thanks,