Face Recognition
Face recognition AI identifies or verifies a person from their face. It is one of the most widely deployed computer vision applications.
10 min•By Priygop Team•Updated 2026
How Face Recognition Works
Face recognition has three steps:
- 1Face detection: find where faces are in the image (bounding boxes)
- 2Face alignment: standardize the face position (crop, rotate to center)
- 3Face embedding: convert the face into a compact numerical representation (a vector of numbers that captures the unique facial features)
Then, to recognize a person: compare their face embedding to a database of known embeddings. The closest match is the predicted person.
Diagram
Loading diagram…
Deep Learning ⊂ Machine Learning ⊂ Artificial Intelligence
Face Recognition in Simple Code
Face Recognition in Simple Code
# Simplified face recognition illustration
# Real systems use deep CNN models to compute face embeddings
import math
def fake_face_embedding(face_id):
"""
In real systems, a CNN computes a 128-512 dimensional vector.
We use tiny 3D vectors here to illustrate the concept.
"""
embeddings = {
"Alice": [0.82, 0.11, 0.45],
"Bob": [0.21, 0.93, 0.12],
"Charlie": [0.55, 0.48, 0.71],
"Unknown": [0.90, 0.15, 0.40], # close to Alice
}
return embeddings.get(face_id, [0, 0, 0])
def euclidean_distance(vec1, vec2):
"""Distance between two face embeddings."""
return math.sqrt(sum((a - b)**2 for a, b in zip(vec1, vec2)))
# Known faces in database
database = {
"Alice": fake_face_embedding("Alice"),
"Bob": fake_face_embedding("Bob"),
"Charlie": fake_face_embedding("Charlie"),
}
# Try to recognize an unknown face
def recognize_face(face_embedding, threshold=0.3):
best_match = None
best_distance = float("inf")
for name, known_embedding in database.items():
distance = euclidean_distance(face_embedding, known_embedding)
if distance < best_distance:
best_distance = distance
best_match = name
if best_distance <= threshold:
return best_match, best_distance
else:
return "Unknown person", best_distance
# Test recognition
test_faces = {
"Alice's face": fake_face_embedding("Alice"),
"Bob's face": fake_face_embedding("Bob"),
"Stranger's face": fake_face_embedding("Unknown"),
}
print("Face Recognition Results:")
print()
for description, embedding in test_faces.items():
match, distance = recognize_face(embedding)
print(f" {description}:")
print(f" Matched to: {match} (distance: {distance:.3f})")Important Note on Privacy
Warning
Face recognition raises significant privacy concerns. In many countries, using face recognition without consent is illegal. Before building or deploying any face recognition system, understand the laws in your region and the ethical implications. We will cover AI ethics in Module 12.