Created
February 8, 2019 21:58
-
-
Save jamesonthecrow/0204b0f0ce10d2969d211b3d6f25e590 to your computer and use it in GitHub Desktop.
This file contains 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
class ViewController: UIViewController { | |
var cameraView: UIImageView! | |
var maskView: UIImageView! | |
override func viewDidLoad() { | |
// ... | |
cameraView = UIImageView(frame: view.bounds) | |
cameraView.contentMode = .scaleAspectFill | |
maskView = UIImageView(frame: view.bounds) | |
maskView.contentMode = .scaleAspectFill | |
cameraView.mask = maskView | |
// ... | |
} | |
extension ViewController: AVCaptureVideoDataOutputSampleBufferDelegate { | |
func captureOutput(_ output: AVCaptureOutput, didOutput sampleBuffer: CMSampleBuffer, from connection: AVCaptureConnection) { | |
let image = FritzVisionImage(buffer: sampleBuffer) | |
let options = FritzVisionSegmentationModelOptions(cropAndScaleOption: .scaleFit) | |
visionModel.predict(image, options: options) { [weak self] (mask, error) in | |
guard let mask = mask, let imageBuffer = CMSampleBufferGetImageBuffer(sampleBuffer) else { return } | |
DispatchQueue.main.async { | |
self?.cameraView.image = UIImage(pixelBuffer: imageBuffer) | |
self?.maskView.image = mask.toImageMask(of: FritzVisionPeopleClass.person, threshold: 0.7, minThresholdAccepted: 0.25) | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment