Face Detection in iOS

To play, in face with vision

In iOS detecting a face from image is very easy with VISION

Yes vision giving some super power for iOS developers (Like infinity stone).

my other blog detecting text from image using vision

Step -1

import Vision

step -2

vision need image as cgimage so image into cgimage

guard let cgImage = yourImage.image?.cgImage else {return }

step -3

request handling with VNImageRequestHandler .

let handler = VNImageRequestHandler(cgImage: cgImage, options: [:])do {try handler.perform([request])} catch let reqErr {print("Error", reqErr)}

VNDetectFaceRectanglesRequest will do the rest works

let request = VNDetectFaceRectanglesRequest { (req, err) inif let err = err {print("Error in Pic", err)return}req.results?.forEach({ (res) inguard let faceObservation = res as? VNFaceObservation else {return}print(faceObservation.boundingBox)})}

thats it. Now face VNFaceObservation will give the frame of face in the image like (0.4031423330307007, 0.6201969385147095, 0.1809350848197937, 0.15218837559223175)

with these axis we get where the face take places.

It will support for multi faces in image too, Thats why we use foreach

If any mistake or you need to shout me, comments session in always opened

நன்றி வணக்கம் || Thank you




Insane || iOS developer

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

【SwiftUI】 Manage Custom Dialog

WhatsApp to get message reactions on iPhone, Android soon: Report

Swift Review — Closures(1)

Complex SwiftUI App Tutorial. Part 1. Designing Model

How to Use Apple’s New SF Symbols in Your Applications

Understand Copy-on-Write in Swift 5

Shared Focus plan in Viva Insights, Walkie-Talkie GA for iOS

Swift. Closures

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Tony Wilson jesuraj

Tony Wilson jesuraj

Insane || iOS developer

More from Medium

Use async URLSession with server-side Swift

Building a FaceTime app for iOS using 100ms

Combine -101: Introduction to Basics & Terms

Batch Convert XCode String files, from utf-16 to utf-8