May 21, 2022 1

 

By – Anurag Vishwakarma

With new innovations and wide adoption of hardware and software, the conventional ways of doing business are getting replaced with the technology in ways no one had thought in the recent past were possible. 

These systems generate a huge amount of data, which has to be processed to extract information from it, then used to make important business decisions. 

KYC authentication system is one such system in place which validates the KYC details received by the banks from the end-user. Received data can be of the following types: 

  1. Images 
  2. Videos 
  3. Text/Form 

Images uploaded by users are verified by matching faces in images to their KYC documents. Videos and text will also get processed and verified. 

In this article, we will be talking about a few techniques that can be used in facial image preprocessing to increase model accuracy.

Prerequisites 

In order to get started with the pre-processing techniques, let us first take a look at the main processes involved in the facial recognition system pipeline. 

  1. Face detection and alignment: Face detection is used to obtain the face coordinates in an uploaded image and document.
  2. Facial feature extraction: Facial feature extraction is the process of extracting face component features. Face embeddings of both faces are obtained from the recognition model. 
  3. Face matching or distance calculation: The distance between embeddings is then calculated. The distance calculated is then checked with the threshold we set for our system. 

The threshold is a value that acts as a border between matched and non-matched cases. Every distance that falls from 0 to threshold is considered matched and any value more than the threshold is considered as not-matched, which means smaller difference between faces will result in greater match confidence. 

Method 

Here, We will be using OpenCV in python for image processing. Firstly, we will load an image for preprocessing and face detection.

# import opencv library in python 

# load an image 

import cv2 

import numpy as np 

# cv2 imread function takes absolute image url as argument image = cv2.imread(‘imagewithface1.jpeg’

Once an image has been read, it is loaded into the image variable as a numpy array. 

There are multiple points in the process where we can introduce our preprocessing, such as –

1. Pre Detection Phase:

The following preprocessing techniques can be used in this phase – 

  • Image resizing: Resizing an image before feeding it to a deep learning model can be helpful. Most of the images uploaded to the system are directly captured from the user’s device and are of high quality. Resizing the image to an expected/optimized size as per a detection model can help boost model accuracy as well as save detection time.

Resizing is done using a process called interpolation. There exist four types of interpolation. They are: 

  1. INTER_NEAREST – a nearest-neighbor interpolation
  2. INTER_LINEAR – a bilinear interpolation (used by default)
  3. INTER_AREA – resampling using pixel area relation. It may be a preferred method for image decimation, as it gives moire’-free results. But when the image is zoomed, it is similar to theINTER_NEAREST method.
  4. INTER_CUBIC – a bicubic interpolation over 4×4 pixel neighborhood 
  5. INTER_LANCZOS4 – a Lanczos interpolation over 8×8 pixel neighborhood 

We will be using ‘INTER_AREA’ interpolation in our case. 

# resize image to certain width and height 

image_resized = cv2.resize(image, (<width>, <height>), interpolation=cv2.INTER_AREA) 

  • Converting image to grayscale: Converting the image to grayscale is recommended before feeding it to the face detection model. Converting an RGB image to grayscale reduces the noise and destruction from an image by reducing the channels.

# Convert BGR to grayscale

 image_gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)

2. Detection Phase:

In the detection phase, the preprocessed image is feeded to the model. Multipl detections can be done in this phase:

  • Simple Face detection: This model is trained to detect faces in an image provided. A list of bounding boxes is given as output.
  •  Eye and other face landmark detection: In these models, the face is detected with the facial landmarks like eyes, nose, jaw etc.

3. Post Detection Phase: 

  • Eye-level based face alignment correction: Eye-level correction can only be done when we have eye landmarks from the detection model. These landmarks are used to make face alignment corrections in cases where the face is rotated by some angle. 

This is done by computing the angle between the centers of the left and right eye. Once we have an angle, we can tilt back the image to correct the alignment.

# leftEye – left eye landmarks mean 

# rightEye – right eye landmarks mean 

leftEye = leftEyeLndmrks.mean(axis=0).astype(“int”) rightEye = rightEyeLndmrks.mean(axis=0).astype(“int”

# compute diffY and diffX 

diffY = rightEye[1] – leftEye[1] 

diffX = rightEye[0] – leftEye[0] 

angle = np.degrees(np.arctan2(diffY, diffX)) – 180 

  • Crop face using face coordinates: If the face is detected in an image, the detection coordinates is given by the model, face is then cropped using those coordinates after which the cropped face is given to another model for feature extraction process. 

# crop face using bounding box 

# model will return arrays of boxes 

# f = [[x, y, w, h], [x1, y1, w1, h1]face = image[y:y + h, x:x + w] 

  • Image normalization: Normalization is another technique used to improve the accuracy of face recognition. Image normalization is a process that changes the range of pixel intensity values.Normalization is often used in an image with poor lighting conditions.

# define a mat of size 

normMat = np.zeros((300, 300)) 

# face normalization 

normalizedFace = cv2.normalize(face, normMat, 0, 255, cv2.NORM_MINMAX) 

Conclusion 

All of the above preprocessing techniques are well known and widely used. Using the right combination of the above methods as per the functional requirements, the accurate face detection and match confidence can be achieved. 

Apart from these techniques, we use smart image processing methods wherein the preprocessing and postprocessing are done with high precision levels with the help of advanced deep learning algorithms which are trained on a large number of datasets specifically for this task. 

Facial recognition technology has changed and will keep changing and optimizing the processes in unimaginable ways for the benefit of everyone.

Leave a comment

Comments

  1. Well written!!!