Guest User

Untitled

a guest
Aug 15th, 2018
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.18 KB | None | 0 0
  1. // MARK: - Lifecycle
  2. extension ViewController {
  3. override func viewWillAppear(_ animated: Bool) {
  4. super.viewWillAppear(animated)
  5. setupAR()
  6. setupML()
  7. }
  8.  
  9. override func viewWillDisappear(_ animated: Bool) {
  10. super.viewWillDisappear(animated)
  11. sceneView.session.pause()
  12. }
  13. }
  14.  
  15. // MARK: - Setup
  16. extension ViewController {
  17. private func setupAR() {
  18.  
  19. let tapGestureRecognizer = UITapGestureRecognizer(target: self, action: #selector(tapped))
  20. sceneView.addGestureRecognizer(tapGestureRecognizer)
  21.  
  22. let configuration = ARWorldTrackingConfiguration()
  23. sceneView.session.run(configuration)
  24. }
  25.  
  26. private func setupML() {
  27. guard let selectedModel = try? VNCoreMLModel(for: example_5s0_hand_model().model) else {
  28. fatalError("Could not load model.")
  29. }
  30.  
  31. let classificationRequest = VNCoreMLRequest(model: selectedModel,
  32. completionHandler: classificationCompleteHandler)
  33. classificationRequest.imageCropAndScaleOption = VNImageCropAndScaleOption.centerCrop
  34. visionRequests = [classificationRequest]
  35.  
  36. loopCoreMLUpdate()
  37. }
  38. }
Add Comment
Please, Sign In to add comment