Get RAW Bayer pixel data from CVPixelBufferRef
Asked Answered
H

1

11

I am using AVCaptureSession & AVCapturePhotoOutput to capture RAW photo data from device's camera in the kCVPixelFormatType_14Bayer_RGGB format.

I have got as far as getting the raw photo sample buffer in the AVCapturePhotoCaptureDelegate callback:

func capture(captureOutput: AVCapturePhotoOutput,
             didFinishProcessingRawPhotoSampleBuffer rawSampleBuffer: CMSampleBuffer?,
             previewPhotoSampleBuffer: CMSampleBuffer?,
             resolvedSettings: AVCaptureResolvedPhotoSettings,
             bracketSettings: AVCaptureBracketedStillImageSettings?,
             error: Error?) {

  guard let rawSampleBuffer = rawSampleBuffer else { return }

  guard let pixelBuffer = CMSampleBufferGetImageBuffer(rawSampleBuffer) else { return }
}

I am now attempting to follow the answers to this question to obtain pixel values from the CVPixelBufferRef but I cannot work out how to do this when using the 14 bit Bayer RGGB pixel format as opposed to the 32 bit RGB format mentioned in the answers.

Hughie answered 25/5, 2017 at 16:26 Comment(2)
Did you find an answer to this?Bremer
I did not get any answerHughie
S
1

First you need to find out the "Pixel format type" of the buffer. This is done with the CVPixelBufferGetPixelFormatType function.

The available types are listed here. In your case I'm guessing kCVPixelFormatType_14Bayer_BGGR.

Then you need to know how the data is stored. According to What is a CVPixelBuffer in iOS? it is

"Bayer 14-bit Little-Endian, packed in 16-bits, ordered R G R G... alternating with G B G B..."

Then you extract the pixels for Uint16 the same way they did for Uint8 in Get pixel value from CVPixelBufferRef in Swift.

Settera answered 18/10, 2019 at 11:33 Comment(0)

© 2022 - 2025 — McMap. All rights reserved.