3

我正在使用以下委托方法AVCaptureVideoDataOutputSampleBufferDelegate以自定义方式显示来自 iPhone 相机的视频。UIView

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

我希望能够从图像中提取一些有用的信息,例如曝光、颜色、阈值。

访问此类信息的最佳方式是什么?

4

2 回答 2

2

从样本缓冲区中提取元数据附件。您可以在它的元数据中找到曝光、颜色等。像这样的东西:

NSDictionary *exifDictionary = (NSDictionary*)CMGetAttachment(sampleBuffer, kCGImagePropertyExifDictionary, NULL);
于 2012-05-02T17:12:40.673 回答
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);
  }
}
于 2012-05-02T17:12:29.063 回答