I am using Vision framework for iOS 11 to detect text on image.
The texts are getting detected successfully, but how we can get the detected text?
Translate text within a photo or image Open the Photos app and select a photo, or select an image online. Touch and hold a word and move the grab points to adjust the selection. Tap Translate.
Optical Character Recognition (OCR) The Vision API can detect and extract text from images. There are two annotation features that support optical character recognition (OCR): TEXT_DETECTION detects and extracts text from any image.
The Vision framework performs face and face landmark detection, text detection, barcode recognition, image registration, and general feature tracking. Vision also allows the use of custom Core ML models for tasks like classification or object detection.
In Apple Vision you can easily extract text from image using VNRecognizeTextRequest class, allowing you to make an image analysis request that finds and recognizes text in an image.
VNRecognizeTextRequest
works starting from iOS 13.0 and macOS 10.15.
Here's a code snippet showing you how to do it:
let requestHandler = VNImageRequestHandler(url: imageURL, options: [:]) let request = VNRecognizeTextRequest { (request, error) in guard let observations = request.results as? [VNRecognizedTextObservation] else { return } for observation in observations { let topCandidate: [VNRecognizedText] = observation.topCandidates(1) if let recognizedText: VNRecognizedText = topCandidate.first { label.text = recognizedText.string } } }
Then you have to assign a value for recognitionLevel
instance property:
// non-realtime asynchronous but accurate text recognition request.recognitionLevel = VNRequestTextRecognitionLevel.accurate // nearly realtime but not-accurate text recognition request.recognitionLevel = VNRequestTextRecognitionLevel.fast try? requestHandler.perform([request])
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With