iOS获取camera的yuv数据

本文介绍了如何在iOS应用中获取Camera的YUV数据。通过设置videoSettings为kCVPixelFormatType_420YpCbCr8BiPlanarFullRange,然后在捕获输出的回调中,利用CMSampleBufferGetImageBuffer和CVPixelBufferGetBaseAddressOfPlane获取YUV数据的地址。需要注意的是,CVPixelBufferGetBaseAddress获取的地址并不是Y分量的起始位置,直接保存会导致16字节的错位。此外,CVPixelBufferGetDataSize的值大于实际大小。
摘要由CSDN通过智能技术生成
首先要设置输出格式:

 [videoOut setVideoSettings:[NSDictionary dictionaryWithObject:

[NSNumber numberWithInt:kCVPixelFormatType_420YpCbCr8BiPlanarFullRange]                                                           forKey:(NSString*)kCVPixelBufferPixelFormatTypeKey]];

在回调中:

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

CVImageBufferRef pixelBuffer =  CMSampleBufferGetImageBuffer(sampleBuffer);

CVPixelBufferLockBaseAddress(pixelBuffer, 0);

void *baseAddress = CVPixelBufferGetBaseAddressOfPlane(pixelBuffer,0);

CVPixelBufferUnlockBaseAddress(pixelBuffer, 0);

}

baseAddress就是yuv数据的地址,注意,用CVPixelBufferGetBaseAddress获取的并不是

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值