Page 32 - MSDN Magazine, November 2019
P. 32

ArtificiAlly intelligent FRANK LA VIGNE Exploring Facial Detection and Recognition
Humans are uniquely adept at detecting and recognizing faces, and face recognition is among the first cognitive skills that humans develop. In fact, we’re so good at this that we often perceive faces where there are none—a phenomenon known as pareidolia. In engineering terms, face detection algorithms in the human brain are prone to false positives. It’s taken computer science a con- siderable amount of time to develop algorithms that can detect faces and accurately identify people based solely on their facial appearance, but now that it’s happened, it’s provoking an import- ant ethical and legal debate.
This isn’t my first dance with face recognition. In my November 2016 Modern Apps column (msdn.com/magazine/mt788628), I used a function built into the Universal Windows Platform (UWP) to detect faces in images captured by a camera. Exploring how the built-in detection system actually recognized faces was beyond the scope of that article at the time, but now I’ll explore in some detailhowfacialdetectionandrecognitionworks.Yes,theCogni- tive Services Face API (bit.ly/2l0d5y1) can perform all these tasks for you, but I wanted to look closer at how the underlying mechanisms work. Doing so gave me a greater appreciation of the Face API.
Detecting Faces
It’s important to point out two distinct terms that are often used interchangeably: face detection and
face recognition. Face detection, as the
name implies, is limited to detecting
the presence of faces in an image. Face recognition involves discerning unique facial characteristics (such as location and shape of the eyes, nose, mouth) to identify individuals based solely on their facial appearance.
Finding faces in images was a prob- lem that eluded computer science until the early 2000s, when researchers Paul Viola and Michael Jones pioneered an algorithm that now bears their name. The Viola-Jones algorithm scans an image using a rectangular filter look- ing for contrasting patterns of light and
dark. While prone to false positives, Viola-Jones is fast and ideal for low-power and battery-driven devices. For an in-depth expla- nation of the Viola-Jones algorithm, I recommend the following YouTube video: youtu.be/uEJ71VlUmMQ.
Another approach to detecting faces is the Histogram of Oriented Gradients (HOG), which analyzes each pixel in an image and its immediate neighboring pixels looking for changes from light to dark. This captures two points of data: the magnitude and the direction of the change from light to dark. This has the end effect of finding the edges in an image and ignoring smoother areas where there are little differences between pixels. The next step is to break down the image into smaller units, say 16 x 16 pixels, and then average out the magnitude and direction values. This reduces the data significantly and provides a bit of noise reduction. Noise, in this context, means any changes from light to dark that aren’t of interest to the algorithm. By taking an average over a set of pixels,weblurouttheminorvariationsinanimage,suchassub- tle shadows, and are left with only the major differences that tend to denote the edges of objects.
For a more in-depth look at this algorithm, check out this tuto- rial: bit.ly/2mkjCne. While it focuses on using HOG in the context of the OpenCV library, the algorithm and the mathematics behind it are the same.
Code download available at bit.ly/2kKIxjC.
20 msdn magazine
Figure 1 The Author with a Face Bounding Box (Left) and Facial Landmark Points (Right)


































































































   30   31   32   33   34