Ask Your Question

kouohhashi's profile - activity

2020-03-22 16:00:24 -0600 received badge  Popular Question (source)
2015-02-20 11:20:22 -0600 asked a question 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,