Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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
You can’t perform that action at this time.