AI Course
Lesson 88: Face Recognition
Face recognition is a computer vision technique that identifies or verifies a person using their facial features. Unlike face detection, which only finds faces in an image, face recognition answers the question of who the person is.
This technology has become common because human faces contain unique patterns that can be learned and compared by machines.
Real-World Connection
Face recognition is used to unlock smartphones, verify identity at airports, tag people in photos, monitor attendance, and enhance security systems.
Any application that needs identity verification without physical contact relies on face recognition.
What Is Face Recognition?
Face recognition is the process of comparing a detected face with known faces stored in a database and finding the closest match.
- Detects a face first
- Extracts facial features
- Matches features against stored data
How Face Recognition Works
Most face recognition systems follow this pipeline:
- Detect the face region in the image
- Align and normalize the face
- Extract feature vectors
- Compare features with known faces
Modern systems use deep learning models to learn facial embeddings automatically.
Face Detection vs Face Recognition
Understanding the difference is important:
- Face Detection: Finds where faces are
- Face Recognition: Identifies whose face it is
Simple Face Recognition Example
Below is a basic example using OpenCV’s LBPH (Local Binary Patterns Histogram) face recognizer.
import cv2
face_cascade = cv2.CascadeClassifier(
cv2.data.haarcascades + "haarcascade_frontalface_default.xml"
)
recognizer = cv2.face.LBPHFaceRecognizer_create()
recognizer.read("trained_model.yml")
image = cv2.imread("test.jpg")
gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
faces = face_cascade.detectMultiScale(gray, 1.3, 5)
for (x, y, w, h) in faces:
face = gray[y:y+h, x:x+w]
label, confidence = recognizer.predict(face)
cv2.rectangle(image, (x,y), (x+w,y+h), (0,255,0), 2)
cv2.putText(image, f"ID: {label}", (x, y-10),
cv2.FONT_HERSHEY_SIMPLEX, 0.8, (0,255,0), 2)
cv2.imshow("Face Recognition", image)
cv2.waitKey(0)
cv2.destroyAllWindows()
What This Code Is Doing
The program detects faces in the image, extracts the face region, and compares it with trained facial data.
The recognizer returns an ID and a confidence score indicating how closely the face matches known identities.
Understanding the Output
The output image shows bounding boxes around faces along with predicted IDs. Lower confidence values usually indicate better matches.
In real applications, IDs are mapped to names or user profiles.
Popular Face Recognition Approaches
- LBPH: Lightweight and simple
- Eigenfaces: PCA-based method
- Deep Face Embeddings: High accuracy using deep learning
Ethical and Privacy Considerations
Face recognition raises privacy and ethical concerns. Responsible systems must ensure transparency, consent, and secure data handling.
Many countries regulate the use of facial recognition technology.
Practice Questions
Practice 1: Face recognition helps determine what about a person?
Practice 2: Which step happens before face recognition?
Practice 3: What is extracted from a face for comparison?
Quick Quiz
Quiz 1: Which task identifies a person by face?
Quiz 2: Which algorithm is used in the example?
Quiz 3: What major concern surrounds face recognition?
Coming up next: Feature Detection — identifying key points and patterns in images.