Last active
August 29, 2019 20:37
-
-
Save jamesonthecrow/fed96d79461ea7efb6d05cdd9b318b62 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
extension PoseEstimationViewController: AVCaptureVideoDataOutputSampleBufferDelegate { | |
func captureOutput(_ output: AVCaptureOutput, didOutput sampleBuffer: CMSampleBuffer, from connection: AVCaptureConnection) { | |
// FritzVisionImage objects offer convient ways to manipulate | |
// images used as input to machine learning models. | |
// You can resize, crop, and scale images to your needs. | |
let image = FritzVisionImage(sampleBuffer: sampleBuffer, connection: connection) | |
// Set options for our pose estimation model using the constants | |
// we initialized earlier in the ViewController. | |
let options = FritzVisionPoseModelOptions() | |
options.minPoseThreshold = poseThreshold | |
// Run the model itself on an input image. | |
guard let poseResult = try? visionModel.predict(image, options: options) else { | |
if let rotated = image.rotate() { | |
let img = UIImage(pixelBuffer: rotated) | |
DispatchQueue.main.async { | |
self?.cameraView.image = img | |
} | |
} | |
return | |
} | |
let poses = poseResult.poses() | |
DispatchQueue.main.async { | |
self.cameraView.image = image.draw(poses: poses) | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment