Making a computer see!!
by: Peter Shoukry

A year ago, one of my friends came to me with an idea: What if we can use facial recognition to find lost kids, the idea is simple right?! Parents of lost kids upload their photos and with a simple mobile app people can photograph kids they suspect are lost and boom… The idea failed for non technical reasons, at least I think it is since we didn’t launch yet, but I wanted to share some of the early stages of working on it doing the face detection and recognition. Of course with deep learning now we can get much better results but I wanted to share those initial experiments anyway. **** ## Face detection To do face recognition you first need to find the face in the picture. My first approach was to simply use OpenCV to do the detection then the recognition but it’s just not accurate at this. don’t believe me check this [video](https://www.youtube.com/watch?v=LsK0hzcEyHI) With this so much false positives I decided to go with dlib in doing the detection part. *** ## Face Recognition Computers just aren’t like us, they can’t take a look at two pictures and say if they are of the same person. Computers are good at math, lots of it, Computers are also good at maximizing and minimizing things and that’s exactly what face recognition is. Its doing some math that will maximize what’s important minimize what’s not and then calculating the distance between two pictures. So to make recognition work we need to: 1- Maximize what’s relevant (main features of the person, special marks, etc…) 2- Minimize the noise( hair, posture, etc… ) 3- Do some math that calculates a specific value that would be maximized if two pictures are similar So I did just that I wrote a simple script that would: 1- Cut the part of the face from a little bit above the eyebrows to the chin and from ear to ear. 2- Affine transform the face to coincide features like nose and eyes of the two pictures on the same place ** An affine transformation is any transformation that preserves collinearity (i.e., all points lying on a line initially still lie on a line after transformation) and ratios of distances (e.g., the midpoint of a line segment remains the midpoint after transformation) 3- Calculate the distance or in other words the probability that this person is the same person in the other image, that part is typically handled by OpenCV. I made a small POC app. First you need to store a couple of pictures of each person in a folder with her/his name and it will identify people with pictures in realtime from the webcam. You can check it [here](https://github.com/pshoukry/facerec/blob/master/facerec.py)