Skip to content

Instantly share code, notes, and snippets.

@jamesonthecrow
Last active August 29, 2019 20:37
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/fed96d79461ea7efb6d05cdd9b318b62 to your computer and use it in GitHub Desktop.
Save jamesonthecrow/fed96d79461ea7efb6d05cdd9b318b62 to your computer and use it in GitHub Desktop.
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