Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

You can convert it to cv::Mat then convert it to IplImage.

//convert from Core Media to Core Video
CVImageBufferRef imageBuffer =  CMSampleBufferGetImageBuffer(sampleBuffer);

CVPixelBufferLockBaseAddress(imageBuffer, 0);

size_t width = CVPixelBufferGetWidthOfPlane(imageBuffer, 0);

size_t height = CVPixelBufferGetHeightOfPlane(imageBuffer, 0);

size_t bytesPerRow = CVPixelBufferGetBytesPerRowOfPlane(imageBuffer, 0);

// extract intensity channel directly

Pixel_8 *lumaBuffer = (Pixel_8*)CVPixelBufferGetBaseAddressOfPlane(imageBuffer, 0);

// render the luma buffer on the layer with CoreGraphics

// (create color space, create graphics context, render buffer)

CGColorSpaceRef grayColorSpace = CGColorSpaceCreateDeviceGray();

CGContextRef context = CGBitmapContextCreate(lumaBuffer, width, height, 8, bytesPerRow, grayColorSpace, kCGImageAlphaNone);

// delegate image processing to the delegate const vImage_Buffer image = {lumaBuffer, height, width, bytesPerRow};

cv::Mat grayImage((int)imagebuf.height, (int)imagebuf.width, CV_8U, imagebuf.data, imagebuf.rowBytes); IplImage* img = new IplImage(grayImage);

You can convert it to cv::Mat then convert it to IplImage.

//convert from Core Media to Core Video
CVImageBufferRef imageBuffer =  CMSampleBufferGetImageBuffer(sampleBuffer);

CVPixelBufferLockBaseAddress(imageBuffer, 0);

size_t width = CVPixelBufferGetWidthOfPlane(imageBuffer, 0);

size_t height = CVPixelBufferGetHeightOfPlane(imageBuffer, 0);

size_t bytesPerRow = CVPixelBufferGetBytesPerRowOfPlane(imageBuffer, 0);

// extract intensity channel directly

Pixel_8 *lumaBuffer = (Pixel_8*)CVPixelBufferGetBaseAddressOfPlane(imageBuffer, 0);

// render the luma buffer on the layer with CoreGraphics

// (create color space, create graphics context, render buffer)

CGColorSpaceRef grayColorSpace = CGColorSpaceCreateDeviceGray();

CGContextRef context = CGBitmapContextCreate(lumaBuffer, width, height, 8, bytesPerRow, grayColorSpace, kCGImageAlphaNone);

// delegate image processing to the delegate const vImage_Buffer image = {lumaBuffer, height, width, bytesPerRow};

cv::Mat grayImage((int)imagebuf.height, (int)imagebuf.width, CV_8U, imagebuf.data, imagebuf.rowBytes);  IplImage* img = new IplImage(grayImage);