Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Apple Vision framework – Text extraction from image

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?

like image 931
Abhishek Avatar asked Jun 15 '17 11:06

Abhishek


People also ask

How do I identify text in a picture Apple?

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.

How can I identify text in an image?

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.

How does Apple vision framework work?

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.


1 Answers

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]) 
like image 169
Andy Jazz Avatar answered Oct 19 '22 16:10

Andy Jazz