Created
May 15, 2019 04:17
-
-
Save jamesonthecrow/8a81d2d7733d921ba9338b05c8f05ea5 to your computer and use it in GitHub Desktop.
Pet Segmentation iOS View Controller with Fritz (www.fritz.ai)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ... | |
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