fbpx
Get In Touch
1201 3rd Avenue Seattle, WA 98101, US
(HQ) Av. Punto Sur 31, Tlajomulco de Zúñiga, Jal 45050, MX
Carrera 11B # 99 - 25, Btá, 110221, CO
Let's talk
hello@inmediatum.com
Ph: +1 (650) 603 0883
Sales attention M - F 9am - 5pm (CT)
Get support
Careers
Endless inspiration and meaningful work
See open positions
Back

Python – Face recognition from scratch

How to make a Face recognition from scratch? As one of the most successful applications of image analysis, facial recognition allows a person to be identified by analyzing the biometric characteristics of their face and has recently received significant attention.

Face recognition systems have become part of our daily lives. The face is used in different parts of the world to unlock mobiles, for certain airport controls, to be able to withdraw money at ATMs, make payments at establishments, or even identify suspects in events with many people as did the singer Taylor Swift in a Los Angeles concert in 2018. It is due to the availability of viable technologies, including mobile solutions.

Now, let’s learn to perform easy recognition in an easy way with python.

Let’s start

First, we will start with install dependencies

In your terminal:

$ pip face_recognition

Yes, just that library need for make face recognition from scratch.

IMPORTANT: This library work with MacOS and Linux, Windows is no supported.

Now the code

import face_recognition

know_image = face_recognition.load_image_file("your_photo.jpg")
unknown_image = face_recognition.load_image_file("unknown.jpg")

try:
   know_face_encoding = face_recognition.face_encodings(know_image)[0]
   unknown_face_encoding = face_recognition.face_encodings(unknown_image)[0]
except IndexError:
   print("I wasn't able to locate any faces in at least one of the images. Check the image files. Aborting...")
   quit()

known_faces = [
    know_face_encoding,
]

results = face_recognition.compare_faces(known_faces, unknown_face_encoding)

if(results[0]):
    print("I found Guido in the image")
else:
    print("Unknown person")


I use this image for training my algorithm:

That is our face to detect, first we save his face and also that of a stranger (it will be the one that will be compared to our first image)

Try use this image:

logistica de salida

Result:

"Unknown person"

This result is because that face is not equal to that of the first image, now try with first image like unknown person, result:

"I found Guido in the image"

 

You need more…?

Here I leave the library repository, there are more examples here, also real time recognition is possible.

GitHub: https://github.com/ageitgey/face_recognition.

Face recognition opens up enormous opportunities for the creation of new aplication that can be great help for different industries, including retail(advertising impact),healthcare (patient pain levels), , and public safety(identifying risk). 

If you are interested in how it works Face recognition or learning more about other technologies in trend suscribe to our blog for keep you up to date.

Luis Estrada
Luis Estrada

We use cookies to give you the best experience. Cookie Policy