How to create CVImageBufferRef from cv:Mat

asked 2015-02-20 11:18:13 -0600

kouohhashi gravatar image

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,

edit retag flag offensive close merge delete

Comments

Hi ! I'm also interested by doing that. Did you find a way finally ? Thank

lilouch123 gravatar imagelilouch123 ( 2016-07-18 03:08:41 -0600 )edit

My answer is here. http://stackoverflow.com/a/43465531/6933079 (http://stackoverflow.com/a/43465531/6...)

newinh gravatar imagenewinh ( 2017-04-18 03:26:05 -0600 )edit