Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- @IBOutlet weak var scanAreaImage: UIImageView!
- var regionOfInterest: CGRect!
- let someRect: CGRect = scanAreaImage.frame
- regionOfInterest = someRect
- func highlightLetters(box: VNRectangleObservation) {
- let xCord = box.topLeft.x * (cameraPreviewlayer?.frame.size.width)!
- let yCord = (1 - box.topLeft.y) * (cameraPreviewlayer?.frame.size.height)!
- let width = (box.topRight.x - box.bottomLeft.x) * (cameraPreviewlayer?.frame.size.width)!
- let height = (box.topLeft.y - box.bottomLeft.y) * (cameraPreviewlayer?.frame.size.height)!
- // This is the section I Added for the rec of interest detection zone.
- //////////////////////////////////////////////
- let wordRect = CGRect(x: xCord, y: yCord, width: width, height: height)
- guard regionOfInterest.contains(wordRect.origin) else { return } // only draw a box if the orgin of the word box is within the regionOfInterest
- // regionOfInterest being the cgRect you created earlier
- //////////////////////////////////////////////
- let outline = CALayer()
- outline.frame = CGRect(x: xCord, y: yCord, width: width, height: height)
- outline.borderWidth = 1.0
- if textColour == 1 {
- outline.borderColor = UIColor.blue.cgColor
- }else {
- outline.borderColor = UIColor.clear.cgColor
- }
- cameraPreviewlayer?.addSublayer(outline)
Add Comment
Please, Sign In to add comment