A trainable OpenCV face recognition project with practical CLI workflows for:
- dataset analysis,
- model training and evaluation,
- single-image and batch directory inference,
- webcam live recognition.
- Multiple recognizers: LBPH, Eigenfaces, Fisherfaces.
- Unknown-person rejection: configurable confidence threshold to label low-confidence predictions as
Unknown. - Dataset analyzer: reports class balance and warns about classes with too few samples.
- Evaluation artifacts: confusion matrix image + JSON report.
- Model card export: creates
MODEL_CARD.mdwith training metadata. - Batch inference: run prediction over an image directory and export JSON.
- Optional annotated outputs: save predicted images with boxes/labels.
pip install -r requirements.txtImportant:
opencv-contrib-pythonis required because this project usescv2.face.*APIs.
face_recognition_system.py– core recognizer + CLIsystem_test_script.py– smoke checksrequirements.txt– dependenciespackage_project.py– create distributable ZIP archiveweb_interface.py– Streamlit web UI
dataset/
alice/
img1.jpg
img2.jpg
bob/
img1.jpg
Use --structure person_folders.
dataset/
alice_1.jpg
alice_2.jpg
bob_1.jpg
Use --structure flat_with_labels.
dataset/
labels.csv
image1.jpg
image2.jpg
labels.csv must have columns: image,person
python face_recognition_system.py \
--analyze-dataset sample_test_faces \
--structure person_folderspython face_recognition_system.py \
--train \
--dataset sample_test_faces \
--structure person_folders \
--model lbph \
--validation-split 0.2 \
--unknown-threshold 55python face_recognition_system.py \
--evaluate sample_test_faces \
--structure person_folders \
--output-json reports/test_eval.jsonpython face_recognition_system.py \
--predict-image my_test.jpg \
--save-annotated \
--annotated-dir outputs/annotated \
--output-json outputs/single_prediction.jsonpython face_recognition_system.py \
--predict-dir incoming_images \
--save-annotated \
--annotated-dir outputs/annotated \
--output-json outputs/batch_predictions.jsonpython face_recognition_system.py --live --camera-id 0python package_project.pyThis generates Face-Recognition-System.zip with core project files.
streamlit run web_interface.pyOpen the local URL shown in terminal (usually http://localhost:8501).
python system_test_script.pyOptional webcam checks:
python system_test_script.py --with-camerapython face_recognition_system.py --help
python system_test_script.pyIf dependencies are installed, help should render and smoke tests should pass. Camera checks are optional and depend on hardware availability.
- add liveness detection / anti-spoofing,
- switch to embedding-based recognition (ArcFace/FaceNet) for large-scale identity search,
- add API service (FastAPI) for production integration,
- add data governance, consent, and auditing pipeline.