我正在使用AVCaptureVideoDataOutputSampleBufferDelegate
使用以下委托方法在自定义UIView
中显示来自iPhone相机的视频。
- (void)captureOutput:(AVCaptureOutput *)captureOutput didOutputSampleBuffer:(CMSampleBufferRef)sampleBuffer fromConnection:(AVCaptureConnection *)connection
我希望能够从图像中提取一些有用的信息,例如曝光,颜色,阈值。
访问此类信息的最佳方式是什么?
答案 0 :(得分:2)
从示例缓冲区中提取元数据附件。您可以在其元数据中找到曝光,颜色等。像这样的东西:
NSDictionary *exifDictionary = (NSDictionary*)CMGetAttachment(sampleBuffer, kCGImagePropertyExifDictionary, NULL);
答案 1 :(得分:1)
您可以使用以下代码访问基础像素数据:
CVPixelBufferRef pixelBuffer = CMSampleBufferGetImageBuffer(sampleBuffer);
CVReturn lock = CVPixelBufferLockBaseAddress(pixelBuffer, 0);
if (lock == kCVReturnSuccess) {
int w = 0;
int h = 0;
int r = 0;
int bytesPerPixel = 0;
unsigned char *buffer;
if (CVPixelBufferIsPlanar(pixelBuffer)) {
w = CVPixelBufferGetWidthOfPlane(pixelBuffer, 0);
h = CVPixelBufferGetHeightOfPlane(pixelBuffer, 0);
r = CVPixelBufferGetBytesPerRowOfPlane(pixelBuffer, 0);
bytesPerPixel = r/w;
buffer = CVPixelBufferGetBaseAddressOfPlane(pixelBuffer, 0);
}else {
w = CVPixelBufferGetWidth(pixelBuffer);
h = CVPixelBufferGetHeight(pixelBuffer);
r = CVPixelBufferGetBytesPerRow(pixelBuffer);
bytesPerPixel = r/w;
buffer = CVPixelBufferGetBaseAddress(pixelBuffer);
}
}