Skip to content

About

A Python notebook exploring two computer vision tasks with OpenCV and dlib-based face embeddings: identifying known faces from a small custom database, and detecting people in group photos using a classical HOG + SVM detector.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Repository files navigation

Face Recognition & People Detection

A Python notebook exploring two computer vision tasks with OpenCV and dlib-based face embeddings: identifying known faces from a small custom database, and detecting people in group photos using a classical HOG + SVM detector.

Open In Colab

What it does

1. Face Recognition (identity matching)

  • Encodes each known face into a 128-dimension vector using the face_recognition library (built on dlib's ResNet model).
  • Stores the encodings + labels in a small pandas "database" and saves it to disk as face_db.pkl, so it can be reloaded without re-encoding.
  • A predict(img_name) function loads a new photo, encodes it, and compares it against every entry in the database (tolerance=0.5). If a match is found it returns that person's name; otherwise it returns 'unknown'.

Database (known faces): Messi (2 reference photos), Ronaldo (1 reference photo)

Test results:

Input image Predicted Correct?
messi3.jpg messi Yes
ronaldo2.jpg ronaldo Yes
bale.jpg (not in database) unknown Yes, correctly rejected

2. People Detection

  • Uses OpenCV's built-in HOG descriptor with the default pre-trained pedestrian SVM (cv2.HOGDescriptor_getDefaultPeopleDetector()).
  • Runs detectMultiScale on a group photo (people2.jpg) to find people, then draws bounding boxes around detections with a confidence score above 0.4.

Result on people2.jpg: 4 people detected, with confidence scores of 1.01, 0.98, 0.77, and 0.49 — all above the threshold, so all four got bounding boxes drawn.

People detection result

Tech stack

  • Python
  • face_recognition (dlib-based face embeddings)
  • OpenCV (cv2) — HOG people detector
  • pandas — lightweight in-memory "face database"
  • matplotlib — visualizing results

Files

File Purpose
face_recognition_ai.ipynb Main notebook — both face recognition and people detection
messi.jpg, messi2.jpeg, ronaldo.jpg Reference images used to build the face database
messi3.jpg, ronaldo2.jpg, bale.jpg Test images used to check prediction accuracy
people1.jpg, people2.jpg Group photos used for the people-detection part

Setup

pip install face_recognition dlib opencv-python pandas matplotlib

Note: dlib requires CMake and a C++ compiler to build from source. If installation fails locally, running this notebook in Google Colab (via the badge above) sidesteps that entirely, since Colab has it preinstalled.

Usage

import face_recognition as fr

# Build the database once
img_enc = fr.face_encodings(fr.load_image_file('messi.jpg'))[0]

# Later, identify a new photo
predict('some_new_photo.jpg')  # returns a name or 'unknown'

Limitations

  • The face database only recognizes the specific people it was built with (Messi, Ronaldo) - anyone else returns unknown.
  • Face matching accuracy depends on the tolerance parameter (set to 0.5 here); lowering it makes matches stricter, raising it makes them looser.
  • The HOG people detector is a classical (non-deep-learning) method - accurate for clearly visible, upright people but less reliable with occlusion, unusual poses, or crowded scenes.

About

A Python notebook exploring two computer vision tasks with OpenCV and dlib-based face embeddings: identifying known faces from a small custom database, and detecting people in group photos using a classical HOG + SVM detector.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages