Pregunta

I am using the AVCaptureVideoDataOutputSampleBufferDelegate to display the video from an iPhones camera in a custom UIView with the following delegate method.

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

I would like to be able to pull out some useful information from the image such as Exposure, color, threshold.

What is the best way to access this sort of information?

¿Fue útil?

Solución

Extract the metadata attachment from the sample buffer. You can find Exposure, color, etc. in it's metadata. something like this:

NSDictionary *exifDictionary = (NSDictionary*)CMGetAttachment(sampleBuffer, kCGImagePropertyExifDictionary, NULL);

Otros consejos

You can access the underlying pixel data with this code:

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);
  }
}
Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top