Skip to content

Instantly share code, notes, and snippets.

@giln
Created March 4, 2019 14:36
Show Gist options
  • Save giln/1fd0d2a60f10474ba1e150956a871024 to your computer and use it in GitHub Desktop.
Save giln/1fd0d2a60f10474ba1e150956a871024 to your computer and use it in GitHub Desktop.
ARSessionDelegate
// MARK: - ARSessionDelegate
var currentBuffer: CVPixelBuffer?
func session(_: ARSession, didUpdate frame: ARFrame) {
// We return early if currentBuffer is not nil or the tracking state of camera is not normal
guard currentBuffer == nil, case .normal = frame.camera.trackingState else {
return
}
// Retain the image buffer for Vision processing.
currentBuffer = frame.capturedImage
startDetection()
}
// MARK: - Private functions
private func startDetection() {
// Here we will do our CoreML request on currentBuffer
// Release currentBuffer to allow processing next frame
currentBuffer = nil
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment