I have a videoPreviewLayer that takes up the entire screen.
The AVCaptureSession() has an AVCaptureVideoDataOutput() that records video and provides access to video frames for processing and a AVCapturePhotoOutput() that gives a capture output for still image, Live Photos, and other photography workflows.
The func photoOutput(_ output: AVCapturePhotoOutput, didFinishProcessingPhoto photo: AVCapturePhoto, error: Error?) gives an image upon capture which is easy to work with.
But the func captureOutput(_ output: AVCaptureOutput, didOutput sampleBuffer: CMSampleBuffer, from connection: AVCaptureConnection) returns frames of sampleBuffer type that I need to crop from the center as a square. And I need this output in CVImageBuffer format(input to a CoreML model)
Basically I need center cropped sampleBuffer frames to work with while displaying the videoPreviewLayer that takes up the entire screen.
I tried helper functions to crop CVImageBuffer but have no way of confirming if its indeed center cropped.
Cinta Jose is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.