Guest User

Untitled

a guest
Nov 24th, 2017
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.31 KB | None | 0 0
  1. @IBOutlet weak var scanAreaImage: UIImageView!
  2. var regionOfInterest: CGRect!
  3.  
  4. let someRect: CGRect = scanAreaImage.frame
  5. regionOfInterest = someRect
  6.  
  7. func highlightLetters(box: VNRectangleObservation) {
  8.  
  9. let xCord = box.topLeft.x * (cameraPreviewlayer?.frame.size.width)!
  10. let yCord = (1 - box.topLeft.y) * (cameraPreviewlayer?.frame.size.height)!
  11. let width = (box.topRight.x - box.bottomLeft.x) * (cameraPreviewlayer?.frame.size.width)!
  12. let height = (box.topLeft.y - box.bottomLeft.y) * (cameraPreviewlayer?.frame.size.height)!
  13.  
  14. // This is the section I Added for the rec of interest detection zone.
  15. //////////////////////////////////////////////
  16.  
  17. let wordRect = CGRect(x: xCord, y: yCord, width: width, height: height)
  18. guard regionOfInterest.contains(wordRect.origin) else { return } // only draw a box if the orgin of the word box is within the regionOfInterest
  19.  
  20. // regionOfInterest being the cgRect you created earlier
  21. //////////////////////////////////////////////
  22.  
  23. let outline = CALayer()
  24. outline.frame = CGRect(x: xCord, y: yCord, width: width, height: height)
  25. outline.borderWidth = 1.0
  26. if textColour == 1 {
  27. outline.borderColor = UIColor.blue.cgColor
  28. }else {
  29. outline.borderColor = UIColor.clear.cgColor
  30. }
  31.  
  32. cameraPreviewlayer?.addSublayer(outline)
Add Comment
Please, Sign In to add comment