Can I get useful information from the camera?

I use AVCaptureVideoDataOutputSampleBufferDelegateiPhones to display video from a camera in a custom one UIViewwith the following delegate method.

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

I would like to get some useful information from the image, such as Exposure, color, threshold.

What is the best way to access this information?

+3
source share
2 answers

Extract the metadata attachment from the fetch buffer. You can find exposure, color, etc. In the metadata. something like that:

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

You can access basic 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);
  }
}
+1
source

All Articles