c - iOS开发中,如何从视频数据sampleBuffer中将数据转换成灰度图像数据?
本文介绍了c - iOS开发中,如何从视频数据sampleBuffer中将数据转换成灰度图像数据?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
问 题
项目中用到了人脸识别,目前工作是需要从摄像头中拿数据传入到人脸算法中。
现在数据我通过AVFoundation中的代理方法拿到了原始数据sampleBuffer。
- (void)captureOutput:(AVCaptureOutput *)captureOutput didOutputSampleBuffer:(CMSampleBufferRef)sampleBuffer fromConnection:(AVCaptureConnection *)connection
{
}
我如何从原始数据sampleBuffer中将数据转成算法能接收的灰度图像数据?
解决方案
CVImageBufferRef imageBufferRef=CMSampleBufferGetImageBuffer(sampleBuffer);
CVPixelBufferLockBaseAddress(imageBufferRef, 0);
unsigned char *ptr_image=CVPixelBufferGetBaseAddressOfPlane(imageBufferRef, 0);
unsigned char* dst = (unsigned char *)malloc(sizeof(unsigned char) * 640 * 480 * 4);
其中480 640为传入人脸识别算法的宽和高,具体要看算法要求
这篇关于c - iOS开发中,如何从视频数据sampleBuffer中将数据转换成灰度图像数据?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文