By using this site, you agree to the Privacy Policy and Terms of Use.
Accept
World of SoftwareWorld of SoftwareWorld of Software
  • News
  • Software
  • Mobile
  • Computing
  • Gaming
  • Videos
  • More
    • Gadget
    • Web Stories
    • Trending
    • Press Release
Search
  • Privacy
  • Terms
  • Advertise
  • Contact
Copyright © All Rights Reserved. World of Software.
Reading: Getting Started With Apple’s Vision Framework: A Developer’s Perspective | HackerNoon
Share
Sign In
Notification Show More
Font ResizerAa
World of SoftwareWorld of Software
Font ResizerAa
  • Software
  • Mobile
  • Computing
  • Gadget
  • Gaming
  • Videos
Search
  • News
  • Software
  • Mobile
  • Computing
  • Gaming
  • Videos
  • More
    • Gadget
    • Web Stories
    • Trending
    • Press Release
Have an existing account? Sign In
Follow US
  • Privacy
  • Terms
  • Advertise
  • Contact
Copyright © All Rights Reserved. World of Software.
World of Software > Computing > Getting Started With Apple’s Vision Framework: A Developer’s Perspective | HackerNoon
Computing

Getting Started With Apple’s Vision Framework: A Developer’s Perspective | HackerNoon

News Room
Last updated: 2025/02/19 at 6:47 PM
News Room Published 19 February 2025
Share
SHARE

The Vision framework was introduced by Apple in 2017 at WWDC as part of iOS 11. Its launch marked a turning point in the evolution of machine vision and image analysis, providing developers with native tools to analyze visual content and perform subsequent processing as needed.

In 2017, Vision introduced:

  • Text recognition
  • Face recognition
  • Detection of rectangular shapes
  • Barcode and QR code recognition

Since its debut, Apple has continuously enhanced the Vision framework, ensuring it evolves to meet modern requirements. By the end of 2024, with the release of iOS 18, Vision now offers:

  • Improved text recognition accuracy with support for a large number of languages
  • Detection of faces and their features
  • The ability to analyze movements
  • The ability to recognize poses, including the position of hands and key points of the human body
  • Support for tracking objects in video
  • Improved integration with CoreML for working with custom machine-learning models
  • Deep integration with related frameworks, such as AVKit, ARKit

With the advent of the Vision framework, developers gained the ability to perform advanced image and video analysis tasks natively, without relying on third-party solutions. These capabilities include scanning documents, recognizing text, identifying faces and poses, detecting duplicate images, and automating various processes that streamline business operations.

In this article, we will look at the main scenarios of using Vision with code examples that will help you understand how to work with it, understand that it is not difficult, and start applying it in practice in your applications.

VNRequest

Vision has an abstract class VNRequest that defines data request structures in Vision, and descendant classes implement specific requests to perform specific tasks with an image.

All subclasses inherit the initializer from the VNRequest class.

public init(completionHandler: VNRequestCompletionHandler? = nil)

Which returns the result of processing the request. It is important to clarify that the result of the request will be returned in the same queue in which the request was sent.

Where VNRequestCompletionHandler is a typealias.

public typealias VNRequestCompletionHandler = (VNRequest, (any Error)?) -> Void

Which returns a VNRequest with the results of the request or an Error if the request was not executed due to some system error, incorrect image, etc.

The VNRecognizeTextRequest class from the abstract VNRequest class is designed to handle text recognition requests in images.

Example of implementing a request for text recognition:

import Vision
import UIKit

func recognizeText(from image: UIImage) {
    guard let cgImage = image.cgImage else { return }
    
    let request = VNRecognizeTextRequest { request, error in // 1
        guard let observations = request.results as? [VNRecognizedTextObservation] else { return } // 2
        
        for observation in observations {
            if let topCandidate = observation.topCandidates(1).first {
                print("Recognized text: (topCandidate.string)")
                print("Text boundingBox: (observation.boundingBox)")
                print("Accuracy: (topCandidate.confidence)")
            }
        }
    }
    
    request.recognitionLevel = .accurate
    request.usesLanguageCorrection = true
    
    let handler = VNImageRequestHandler(cgImage: cgImage, options: [:]) // 3
    try? handler.perform([request]) // 3
}
  1. Create a VNRecognizeTextRequest for text recognition.

  2. Receive the results of the text recognition request as arrays of VNRecognizedTextObservation objects.

The VNRecognizedTextObservation object contains:

  • An array of recognized texts (VNRecognizedText().string)
  • Recognition accuracy (VNRecognizedText().confidence)
  • Coordinates of the recognized text on the image (VNRecognizedText().boundingBox)
  1. Create a request for image processing, and send a request for text recognition.

  2. Example: Recognition of tax identification number and passport number when developing your own SDK for document recognition

VNDetectFaceRectanglesRequest

This class finds faces in an image and returns their coordinates.

Example of implementing a face recognition request:

import Vision
import UIKit

func detectFaces(from image: UIImage) {
    guard let cgImage = image.cgImage else { return }
    
    let request = VNDetectFaceRectanglesRequest { request, error in // 1
        guard let results = request.results as? [VNFaceObservation] else { return } // 2
        
        for face in results {
            print("Face detected: (face.boundingBox)")
        }
    }
    
    let handler = VNImageRequestHandler(cgImage: cgImage, options: [:]) // 3
    try? handler.perform([request]) // 3
}
  1. Create a VNDetectFaceRectanglesRequest for face recognition in an image.

  2. Receive the results of the text recognition request as arrays of VNFaceObservation objects.

The VNFaceObservation object contains:

  1. Coordinates of the recognized face VNFaceObservation().boundingBox.

  2. Create a request for image processing and send a request for face recognition.

  3. Example: In banks, there is a KYC onboarding where you have to take a photo with your passport; this way, you can confirm that this is the face of a real person.

VNDetectBarcodesRequest

This class recognizes and reads barcodes and QR codes from an image.

Example of implementing a request for recognizing and reading a barcode and QR code:

import Vision
import UIKit

func detectBarcodes(from image: UIImage) {
    guard let cgImage = image.cgImage else { return }
    
    let request = VNDetectBarcodesRequest { request, error in // 1
        guard let results = request.results as? [VNBarcodeObservation] else { return } // 2
        
        for qrcode in results {
            print("qr code was found: (qrcode.payloadStringValue ?? "not data")")
        }
    }
    
    let handler = VNImageRequestHandler(cgImage: cgImage, options: [:]) // 3
    try? handler.perform([request]) // 3
}
  1. Create a VNDetectBarcodesRequest for recognition.

  2. Get the results of the VNBarcodeObservation object array request.

The VNBarcodeObservation object contains many properties, including:

  1. VNFaceObservation().payloadStringValue – the string value of the barcode or QR code.

  2. Create a request for image processing, and send a request for face recognition.

  3. Example: QR scanner for reading QR codes for payment.

We’ve covered the 3 main types of queries in Vision to help you get started with this powerful tool.

Sign Up For Daily Newsletter

Be keep up! Get the latest breaking news delivered straight to your inbox.
By signing up, you agree to our Terms of Use and acknowledge the data practices in our Privacy Policy. You may unsubscribe at any time.
Share This Article
Facebook Twitter Email Print
Share
What do you think?
Love0
Sad0
Happy0
Sleepy0
Angry0
Dead0
Wink0
Previous Article Quantum computing in cyber security: A double-edged sword | Computer Weekly
Next Article Elon Musk’s X looks to raise exactly what Musk paid for it
Leave a comment

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Stay Connected

248.1k Like
69.1k Follow
134k Pin
54.3k Follow

Latest News

This is your best chance to get a Switch 2 at launch if you didn’t preorder
News
Google finally confirms when we can expect Android 16 to drop
News
Red Hat Enterprise Linux 10 Reaches GA
Computing
Musk joins Trump on Saudi trip
News

You Might also Like

Computing

Red Hat Enterprise Linux 10 Reaches GA

1 Min Read
Computing

TME reports strong subscription growth in Q3, but faces decline in monthly active users · TechNode

2 Min Read
Computing

AMD Begins Process Of Preparing The Linux Kernel For Zen 6 CPUs

2 Min Read
Computing

China’s Baidu could launch commercial self-driving taxi service in UAE: report · TechNode

1 Min Read
//

World of Software is your one-stop website for the latest tech news and updates, follow us now to get the news that matters to you.

Quick Link

  • Privacy Policy
  • Terms of use
  • Advertise
  • Contact

Topics

  • Computing
  • Software
  • Press Release
  • Trending

Sign Up for Our Newsletter

Subscribe to our newsletter to get our newest articles instantly!

World of SoftwareWorld of Software
Follow US
Copyright © All Rights Reserved. World of Software.
Welcome Back!

Sign in to your account

Lost your password?