Instruction 01

Heads up... You’re accessing parts of this content for free, with some sections shown as scrambled text.

Heads up... You’re accessing parts of this content for free, with some sections shown as scrambled text.

Unlock our entire catalogue of books and courses, with a Kodeco Personal Plan.

Unlock now

Whether your app is an accessibility tool, data-entry automation or a document scanner, the ability to recognize and work with text opens new possibilities. Apple’s Vision Framework provides a few request types that are specifically designed for these tasks. Here’s a chart for the main text-related Vision request types along with their response observation types and when they were introduced.

iOS 11

  • VNDetectTextRectanglesRequest and VNTextObservation: Detects regions of text in an image.

iOS 13

  • VNDetectTextRectanglesRequest and VNTextObservation: Performs Optical Character Recognition (OCR) to detect and recognize text.

iOS 15

  • VNRecognizeHandwritingRequest and VNRecognizedTextObservation: Recognizes handwritten text in images.
let textDetectionRequest = VNDetectTextRectanglesRequest { request, error in
  guard let observations = request.results as? [VNTextObservation]
    else { return }
  // Handle detected text rectangles
}
let requestHandler = VNImageRequestHandler(cgImage: inputImage.cgImage!,
  options: [:])

do {
  try? requestHandler.perform([textDetectionRequest])
} catch {
  // Handle the error
}

Differentiating Between VNDetectTextRectanglesRequest and VNRecognizeTextRequest

When the Vision Framework first arrived, VNDetectTextRectanglesRequest was the only option. This request type gave you the bounding boxes of all the areas in an image that likely contain text. If you wanted to actually perform recognition, you had to use a CoreML model.

See forum comments
Download course materials from Github
Previous: Introduction Next: Instruction 02