Skip to content

Instantly share code, notes, and snippets.

@jknthn
Last active June 19, 2017 09:59
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 jknthn/2d4f1eff11f72dbee11dbde1d56e5885 to your computer and use it in GitHub Desktop.
Save jknthn/2d4f1eff11f72dbee11dbde1d56e5885 to your computer and use it in GitHub Desktop.
private let classifier = Resnet50()
func captureOutput(_ output: AVCaptureOutput, didOutput sampleBuffer: CMSampleBuffer, from connection: AVCaptureConnection) {
let imageBuffer = CMSampleBufferGetImageBuffer(sampleBuffer)
let rescaled = rescaledImageRectangle(createUIImage(from: imageBuffer), dimension: inputImageScale)
let rescaledBuffer = createCVPixelBuffer(from: rescaled)
guard let prediction = try? classifier.prediction(image: rescaledBuffer!) else { return }
DispatchQueue.main.async {
self.predictionLabel.text = prediction.classLabel
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment