Skip to content

Instantly share code, notes, and snippets.

@jamesonthecrow
Created May 15, 2019 04:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jamesonthecrow/8a81d2d7733d921ba9338b05c8f05ea5 to your computer and use it in GitHub Desktop.
Save jamesonthecrow/8a81d2d7733d921ba9338b05c8f05ea5 to your computer and use it in GitHub Desktop.
Pet Segmentation iOS View Controller with Fritz (www.fritz.ai)
// ...
import Fritz
class ViewController: UIViewController {
var cameraView: UIImageView!
override func viewDidLoad() {
super.viewDidLoad()
cameraView = UIImageView(frame: view.bounds)
cameraView.contentMode = .scaleAspectFill
view.addSubview(cameraView)
// ... Rest of camera setup
}
override func viewWillLayoutSubviews() {
super.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