Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Pet Segmentation iOS View Controller with Fritz (
// ...
import Fritz
class ViewController: UIViewController {
var cameraView: UIImageView!
override func viewDidLoad() {
cameraView = UIImageView(frame: view.bounds)
cameraView.contentMode = .scaleAspectFill
// ... Rest of camera setup
override func viewWillLayoutSubviews() {
cameraView.frame = view.bounds
extension ViewController: AVCaptureVideoDataOutputSampleBufferDelegate {
func captureOutput(_ output: AVCaptureOutput, didOutput sampleBuffer: CMSampleBuffer, from connection: AVCaptureConnection) {
DispatchQueue.main.async {
guard let imageBuffer = CMSampleBufferGetImageBuffer(sampleBuffer) else { return }
// By importing Fritz, you are able to access a helper extension on UIImage that makes it
// easy to create a UIImage from a CVPixelBuffer.
self.cameraView.image = UIImage(pixelBuffer: imageBuffer)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.