Vision Framework

Sep 18 2024 · Swift 5.10, 6.0, iOS 17.5, 18b4, Xcode 15.4, 16b6

Lesson 03: Exploring Text Detection & Recognition

Demo

Episode complete

Play next episode

Next

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

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

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

Unlock now

Here’s the demo app again. If you want to code along, you can find this version in the Starter folder for the materials for this lesson. When you build and run, you can see there’s a new tab for text recognition. The text recognition will be similar to the face recognition from the previous lesson. After Vision recognizes the text, the user can cycle through the rectangles to see the bounding box in red and also the recognized string for that line.

self?.textRectangles = request.results?.compactMap {
  guard let observation = $0 as? VNRecognizedTextObservation,
        let topCandidate = observation.topCandidates(1).first else { return nil }
  return (observation.boundingBox, topCandidate.string)
} ?? []
import CoreImage
import CoreImage.CIFilterBuiltins
let ciImage = CIImage(cgImage: cgImage)
let exposureAdjustFilter = CIFilter.exposureAdjust()
exposureAdjustFilter.inputImage = ciImage
exposureAdjustFilter.ev = 1.0
guard let exposureAdjustedImage = exposureAdjustFilter.outputImage
  else { return }
let handler = VNImageRequestHandler(ciImage: exposureAdjustedImage, options: [:])
let contrastAdjustFilter = CIFilter.colorControls()
contrastAdjustFilter.inputImage = exposureAdjustedImage
contrastAdjustFilter.contrast = 4
guard let processedImage = contrastAdjustFilter.outputImage else { return }
let handler = VNImageRequestHandler(ciImage: processedImage, options: [:])
See forum comments
Cinema mode Download course materials from Github
Previous: Instruction 02 Next: Conclusion