Guest User

Untitled

a guest
Dec 2nd, 2019
119
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //
  2. // ViewController.swift
  3. // GoogleCodeIn
  4. //
  5. // Created by Marcin on 02/12/2019.
  6. // Copyright © 2019 Marcin. All rights reserved.
  7. //
  8.  
  9. import UIKit
  10. import Firebase
  11. class ViewController: UIViewController, UIImagePickerControllerDelegate,UIPopoverControllerDelegate,UINavigationControllerDelegate {
  12.  
  13. @IBOutlet weak var backInfo: UILabel!
  14. @IBOutlet weak var image: UIImageView!
  15. var picker:UIImagePickerController?=UIImagePickerController()
  16. override func viewDidLoad() {
  17. super.viewDidLoad()
  18. picker?.delegate=self
  19. }
  20.  
  21. @IBAction func openGalleryTapped(_ sender: UIButton) {
  22. picker!.allowsEditing = false
  23. picker!.sourceType = .photoLibrary
  24. present(picker!, animated: true, completion: nil)
  25. }
  26. func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [UIImagePickerController.InfoKey : Any]) {
  27. var chosenImage = info[UIImagePickerController.InfoKey.originalImage] as! UIImage
  28. image.image = chosenImage
  29. backInfo.text? = ""
  30. let labeler = Vision.vision().onDeviceImageLabeler()
  31. let image = VisionImage(image: chosenImage)
  32. labeler.process(image) { labels, error in
  33. guard error == nil, let labels = labels else { return }
  34.  
  35. for label in labels {
  36. let labelText = label.text
  37. self.backInfo.text?.append(labelText)
  38. self.backInfo.text?.append(" ")
  39. }
  40. }
  41.  
  42. dismiss(animated: true, completion: nil)
  43. }
  44.  
  45. }
RAW Paste Data