Vision Framework

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

Lesson 02: Building Basic Vision Requests

Demo 02

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 app you’ve been working with. In this demo, you’ll update the faces tab to recognize faces in an image and draw red rectangles on them. Build and run the app. The classification tab works the same as the last demo, but when you tap the “Detect faces” button, nothing happens.

let rectangles: [CGRect] = request.results?.compactMap { obs in
  guard let observation = obs as? VNFaceObservation else
    { return nil }
  return observation.boundingBox
} ?? []
DispatchQueue.main.async {
  self?.faceRectangles = rectangles
  self?.errorMessage = rectangles.isEmpty
    ? "No faces detected" : nil
}
See forum comments
Cinema mode Download course materials from Github
Previous: Instruction 02 Next: Conclusion