Skip to content
tezvyn:
Menu

Vision Framework: Computer Vision on Apple Devices

Source: developer.apple.comMediumHow cards are made

Vision Framework: Computer Vision on Apple Devices

The Vision framework is your on-device toolkit for understanding images and video. Use it for face detection, text recognition, or barcode scanning without needing ML expertise. Footgun: don't run requests on every frame; it drains the battery.

Why it exists

Before Vision, implementing features like face detection or text recognition required deep expertise in image processing and machine learning, or reliance on third-party libraries. Apple created the Vision framework to provide a standardized, high-performance, on-device solution optimized for its hardware.

The mental model

Think of Vision as a team of expert analysts for images and video. You don't teach them their job; you just hand them an image (a CIImage or CVPixelBuffer) and a task (a VNRequest). For example, you give them a photo and ask them to find all the faces. They do the complex work and return a simple list of observations (VNObservation), like the locations of the faces they found. It's an abstraction layer over complex Core ML models.

How it works

The workflow has three steps. First, you define what you're looking for by creating one or more request objects, like a VNDetectFaceRectanglesRequest or a VNRecognizeTextRequest. Second, you create a request handler, either a VNImageRequestHandler for a single image or a VNSequenceRequestHandler for a video stream. Third, you execute the requests using the handler. The framework processes the image and returns an array of observation objects, which you then interpret to get your results, like bounding boxes or recognized text strings.

When to use it

Use Vision for common, built-in computer vision tasks. This includes detecting faces and facial landmarks (eyes, nose), recognizing text (OCR), tracking objects across multiple video frames, finding barcodes and QR codes, and identifying rectangular objects like documents. It's the default choice for adding these features to an iOS, iPadOS, or macOS app.

When not to use it

Vision is not for identifying custom objects out of the box. If you need to detect a specific dog breed or car model, you must first train a custom Core ML model; Vision can then help you run that model, but it doesn't provide the classification logic itself. Avoid running intensive Vision requests on every single frame of a high-framerate video feed without throttling, as this will cause severe performance issues and battery drain.

One canonical example

Building a document scanner. Your app uses the live camera feed. You create a VNDetectRectanglesRequest and run it on frames from the camera. Vision returns a VNCoreMLRequest with the four corner points of the largest detected rectangle (the document). Your UI can then draw an overlay using these points to guide the user. After the user captures a photo, you use the same corner points to apply a perspective correction filter, creating a perfectly flat, scanned image.

Interview question

Which task requires a custom Core ML model in addition to Vision's built-in capabilities?

  • a.Identifying the specific make and model of a car in a photograph.Correct
  • b.Detecting the presence and location of human faces in a video.
  • c.Locating all rectangular objects, like documents, within a camera feed.
  • d.Reading and extracting text from an image of a receipt.
Why?

The card states that Vision is not for identifying custom objects like specific car models out of the box; this requires a custom Core ML model. The other options are all examples of built-in capabilities of the Vision framework.

Just read this? Test yourself on what you have been reading.

Read the original → developer.apple.com

Put your scrolling time to good use

Learn one idea, try a quiz and save useful cards for revision. Tezvyn makes it easy to learn and stay current in your tech field, a few minutes at a time.

The iPhone app is on the way

We are building it. Until it lands, nothing here is held back from you: every interview card, your saved cards, streaks and the job board all work in Safari, plus hundreds of free practice quizzes of thirty questions each. Sign in and it all carries over to the app the day it arrives.

Want it as an icon? Tap Share at the bottom of Safari, then Add to Home Screen. It opens full screen and the cards you have read stay available offline.

Get it on Google PlayiPhone app coming soon

We are hiring for this. Open roles that interview on ios — each one lists the topics its interview covers.

See open roles