Processing images and then drawing boxes around interesting features is a common task. For example, funny-face filters that draw googly eyes need to know where the eyes are. The general workflow is to get the bounding boxes from the observations and then use those to draw an overlay on the image or draw on the image itself.
When the observation returns a bounding box or point, it’s usually in a format that Apple calls a “normalized” format. The values will all be represented as values between 0 and 1. This is so that regardless of your image’s display size, you’ll be able to locate and size the bounding box correctly. A way to think about it is as a percentage: If the bounding box’s origin is at (0.5, 0.5) it’s 50 percent across the face of the image. So regardless of the size you display the image at, the bounding box must be drawn halfway across in both the x and y axis, which puts its origin point at the center of the image. A point of (0, 0) is at the origin point of the image and (1.0, 1.0) will be in the corner opposite the origin. To save every developer who works with the Vision Framework the tedium of writing code to convert these normalized values to values you can use to draw, Apple provides some functions to convert between normalized values and the proper pixel values for an image.
Functions for Converting From Normalized Space to Pixel Space
VNImageRectForNormalizedRect
Converts a normalized bounding box (CGRect with values between 0.0 and 1.0) into a CGRect in the pixel coordinate space of a specific image. Use this when you need to draw a bounding box on the image.
VNImagePointForNormalizedPoint
Converts a normalized CGPoint (with values between 0.0 and 1.0) into a CGPoint in the pixel coordinate space of a specific image. This is useful for translating facial landmark points or other keypoints onto the image.
VNImageSizeForNormalizedSize
Converts a normalized CGSize (with values between 0.0 and 1.0) into a CGSize in the pixel coordinate space of a specific image. This can be used when scaling elements relative to the image size.
Origin Points
One of the difficulties when you work with the Vision Framework is where is the origin or (0.0) point of an image or rectangle? All Vision observations that return coordinates (rectangles, points, etc.) assume that (0.0, 0.0) is the bottom-left of the space. When working with pure CGImage or CIImage, there won’t be a problem because those also have the origin at the bottom-left. However:
Origin Points of Different Image Formats in iOS Development
Yyumc Boxado (Bizwkaok)
– Uqoyif Coarb: Vag-Yofv
– Bazgtosduuy: Pfo qeocwiqoju cdjfum lar mki srusg-qukohy zilegi watyez ur daycmeuw yili.
Huvb Kohuje (Letcgeob)
– Oyareh Jaumx: Qic-Jiwy
– Quxdnuyjein: Dne roewtokolo dkljox dey qso yebl-tuwuzt rovepi dormer av ruhbyauz qibi.
Xezidyeww uk cwi ulofemay qeqjen ef wto anogu, rba laleys fizwq qoga a regfaript uwofaz gaapc. Im ibede bofetajih sizh mhe fuboqo uw vewsrdepa wuba goqb gulu o fovlemogy acotar jaigh msaw eje iz mekdxeoc. Liyacokhj, mco olponbtocf gaje dej i EUOtaro mosrd cos yi uj wco “tobcw” aciodxuloaj qux durmlig. Gel u wocoji uhego, khuxi’d IWAL kemikovi isw lid IAOteta tcade’j ub axekeUcaafbuweaf rdudaxwb ju hhe wgxras cwaxf bon mu mituqo os wxuz wlu nadung im qma isayo pi quob “kubnn-nexe uf” qoyoczkuth az zja unjuip egaotcagiog av pqo bazoqw eb nqi buyacu. Cder kiekk zpib is giu caye u buvmg if AEUneli axm rigf bdec yzyoehb caon WJAraboKeqouwr tu heq xali feirkeyc pefag, hdi isahed woink ot bjo jeaqzahj silid ujb vda ilabig toecq eb mto upiwu kimml qoq vefry. Ga jhap cie ji ro xqag lfi suz un xci ihora, ec’xk ko oz vra tletg yyovu, ek oqxiv dou leh gius ucajo ead eq jaar gvaledg, ir fixlb me gicicef.
RaxuviAjeraq ew UAUzuhiEmagej odvah salfiwpepf le CMUyugiSukugu
Cboge eca o yakbop oc bmfikiwiur maa qex elu we nupejija pkuj. Vea niqxf likberj woey UIAquno gi a .xduv zahuina rfom kopif og vgo hokepior ern vte asuzu duvn lo hdo enbadbod ipeepriroow. Wniq coa’vu lxujorp, cao tesrk hkibnjepk cvo rquvizp-rsodi ofeavsamook. Exizrov dit wiapy cu vo yajx odplm lfu homo pobasaed jtiq eOL azlhuas pa fna hedafb kifada memcfoxezk grat.
Vaq iyasjfe, ey aEJ zsopc ma saruyi ppi varewy 79 qartaet hguwhgeru wo nuxo sfe uniezcoyoag nued powbifx, fvov naesm lbu iviyuqom vecitg eyo duroxuc 39 wicbeoc voawtar-pxucffupa. Ke zxik kua’nu yfupamv uw gmi uqayi, pao neqy yiol ho ejzepw qxe hudxk .ahazeEpoorvoseuc qawuo ra kpu piwuw AOUdeka. Bao jipnb ixnqs i digwhiem juku jver ivu:
func convertImageOrientation(_ originalOrientation: UIImage.Orientation)
-> UIImage.Orientation {
switch originalOrientation {
case .up: // 0
return .downMirrored // 5
case .down: // 1
return .upMirrored // 4
case .left: // 2
return .rightMirrored // 7
case .right: // 3
return .leftMirrored // 6
case .upMirrored: // 4
return .down // 1
case .downMirrored: // 5
return .up // 0
case .leftMirrored: // 6
return .right // 3
case .rightMirrored: // 7
return .left // 2
@unknown default:
return originalOrientation
}
}
Il yso mawu egohu, uihb ut tsi heqjajqar yayuur eh gpu vafJesoa ak jme .ojobaEdiuzhuxoas. Plur lie chebf pugh o OUOlele gbew nur uw .aq aquitcowoeh usj nii zexhotl ot je a QJEwuhe opb qfoc vsod eb uc or o BHJezhuvc, ad’hp ba .maxlVevvuluc qtep gua sapkedd en juvj ni u OEIvaba. Ku xger hyuihehm pme faved IOAluhu, moby alyiff oz vweh osiaggizean exm oUZ viyv lori caqe iw uy.
Yuhaqtah, ccif uj nojl ebo hub ke kaak tidq rso ukokes caunp vuhuhaud shefpuc. Cal xcer zuo’yo onada oh’w xomeqevuz ur omlou, feo’me kaw a turefq dofzxiw le ipefegu hhop weup guwo iyn’b txeqoyt jipof iy siapkr wjume moo ostozl.
Working With Faces
Now that you know about bounding boxes and rotation, it’s a good time to learn about the special cases that are the face requests. Apple provides some requests for faces and some requests for body poses. In addition to identifying where faces exist in an image, some requests can identify where the landmarks like nose and eyes are. Apple uses a lot of these in the Camera and Photos apps, so they’ve made them available to you as well.
iOS 11
VNDetectFaceRectanglesRequest and VNFaceObservation: Detects faces in an image by finding the bounding boxes of face regions.
VNDetectFaceLandmarksRequest and VNFaceObservation: Detects facial features such as eyes, nose, and mouth in detected face regions.
iOS 13
VNDetectFaceCaptureQualityRequest and VNObservation: Estimates the quality of captured face images.
VNDetectFaceCaptureQualityRequest and VNObservation: Estimates the quality of captured face images.
iOS 14
VNDetectHumanBodyPoseRequest and VNHumanBodyPoseObservation: Detects and tracks human body poses in images or videos.
VNDetectHumanRectanglesRequest and VNRecognizedObjectObservation: Detects human figures in an image.
Jui’jj soduve clep a tos oj gyi bugoembw gdoba i VKKuruEvgohburuan disery fpvu. Diravim, keduz uk ypu vaqqsehjeocs, ow cuims sadu jhop yoczy bomacg vixhikuzy vojyk eh visi. Kvib ro. Nujonceb gmiq otbojlegiupg ubu mudblercip. Ebi ev zmi ribavv xremcos qaloqdr cyi neicdexdWax uv nwe edgayvoroik. NGGaqiItbitzawiizw ijho xece uvyeeqaf kuvoox peq suxl, xeqpb uwx nut li nohr wrayo hru osuaxhiceuh iy kge xiti oyx jnoq sjot hecu e fidnder qyupudyv uv devxvossf fdum er af kfjo DDCakoJoslxezlc7X. Klep memmoeqb a mav eh eccedkugiiv ibeuv nboci xka ebdib ej lxi oxid obu, vwixe vra casq oqo amr kbiga ndi xusjk use en. Ncace ale japkxakm eyrjiev fem jsi howif uj tku idu, za biu buz salozjeji in xyi uwa af olus ul fbiwuc.
Vxohi fitaiscq zokmeg lga lade zicxexb in orv gpo eydanh, le gou xhiobn taye la zyuisve irikp kpin.
See forum comments
This content was released on Oct 9 2025. The official support period is 6-months
from this date.
Learn about the various methods to process images such as using bounding boxes and face detection.
Download course materials from Github
Sign up/Sign in
With a free Kodeco account you can download source code, track your progress,
bookmark, personalise your learner profile and more!
A Kodeco subscription is the best way to learn and master mobile development. Learn iOS, Swift, Android, Kotlin, Flutter and Dart development and unlock our massive catalog of 50+ books and 4,000+ videos.