Skip to content

Instantly share code, notes, and snippets.

@brunomunizaf
Last active August 21, 2018 20:51
Show Gist options
  • Save brunomunizaf/346dcc01a5520b14a5ae61f7aec13d45 to your computer and use it in GitHub Desktop.
Save brunomunizaf/346dcc01a5520b14a5ae61f7aec13d45 to your computer and use it in GitHub Desktop.
Heartbeat AR/ML middle
// MARK: - Lifecycle
extension ViewController {
override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
setupAR()
setupML()
loopCoreMLUpdate()
}
override func viewWillDisappear(_ animated: Bool) {
super.viewWillDisappear(animated)
sceneView.session.pause()
}
}
// MARK: - Setup
extension ViewController {
private func setupAR() {
let tapGestureRecognizer = UITapGestureRecognizer(target: self, action: #selector(tapped))
sceneView.addGestureRecognizer(tapGestureRecognizer)
let configuration = ARWorldTrackingConfiguration()
sceneView.session.run(configuration)
}
private func setupML() {
guard let selectedModel = try? VNCoreMLModel(for: example_5s0_hand_model().model) else {
fatalError("Could not load model.")
}
let classificationRequest = VNCoreMLRequest(model: selectedModel,
completionHandler: classificationCompleteHandler)
visionRequests = [classificationRequest]
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment