首頁  >  問答  >  主體

c - iOS开发中,如何从视频数据sampleBuffer中将数据转换成灰度图像数据?

项目中用到了人脸识别,目前工作是需要从摄像头中拿数据传入到人脸算法中。
现在数据我通过AVFoundation中的代理方法拿到了原始数据sampleBuffer。

- (void)captureOutput:(AVCaptureOutput *)captureOutput didOutputSampleBuffer:(CMSampleBufferRef)sampleBuffer fromConnection:(AVCaptureConnection *)connection
{
    
}

我如何从原始数据sampleBuffer中将数据转成算法能接收的灰度图像数据?

PHPzPHPz2715 天前646

全部回覆(2)我來回復

  • PHPz

    PHPz2017-04-18 09:37:18

    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為傳入人臉辨識演算法的寬與高,具體要看演算法要求

    回覆
    0
  • 黄舟

    黄舟2017-04-18 09:37:18

    我出在也遇到了這個方法,求指導。

    回覆
    0
  • 取消回覆