Python - Face Recognition, Face Detection, Facial recognition script code with demo

Python – Face Recognition, Face Detection, Facial recognition script code with demo.

What is Face Recognition / Detection?

One of the most important applications of face detection.
Recognize and manipulate faces from Python or from the command line with the world simplest face recognition library.
Face recognition describes a biometric technology that goes way beyond recognizing when a human face is present. It actually attempts to establish whose face it is.
The process works using a computer application that captures a digital image of an individual face. and compares it to images from the database of stored records.

Face recognition with OpenCV, Python:

Learn how to perform face recognition in both images and video streams using:

Install this module from pypi using pip:
pip install face_recognition
import face_recognition
image = face_recognition.load_image_file("your_file.jpg")
face_locations = face_recognition.face_locations(image)

Identify faces in pictures:

import face_recognition
image = face_recognition.load_image_file("your_file.jpg")
face_landmarks_list = face_recognition.face_landmarks(image)

Recognize who appears in each photo.

import face_recognition
known_image = face_recognition.load_image_file("biden.jpg")
unknown_image = face_recognition.load_image_file("unknown.jpg")

biden_encoding = face_recognition.face_encodings(known_image)[0]
unknown_encoding = face_recognition.face_encodings(unknown_image)[0]

results = face_recognition.compare_faces([biden_encoding], unknown_encoding)
import face_recognition

picture_of_me = face_recognition.load_image_file("me.jpg")
my_face_encoding = face_recognition.face_encodings(picture_of_me)[0]

# my_face_encoding now contains a universal encoding of my facial features that can be compared to any other picture of a face!

unknown_picture = face_recognition.load_image_file("unknown.jpg")
unknown_face_encoding = face_recognition.face_encodings(unknown_picture)[0]

# Now we can see the two face encodings are of the same person with compare_faces!

results = face_recognition.compare_faces([my_face_encoding], unknown_face_encoding)

if results[0] == True:
  print("It is a picture of me!")
  print("It is not a picture of me!")

For more understanding. Please click here.

Any query? Please share your thoughts in the comments below. Glad to help you!

Was this page helpful? Do not forget to share this post!

Leave a Reply

Your email address will not be published. Required fields are marked *