Skip to content

Face Recognition code to detect faces on live cameras implemented using OpenCV and Dlib.

Notifications You must be signed in to change notification settings

V8V88V8V88/face-recognition

Repository files navigation

Face Recognition Project

Welcome to the Face Recognition project! This repository contains a complete system for face detection and recognition, including trained models, scripts for detection, and test files. The project is built using machine learning models and libraries such as Dlib, OpenCV, and others to detect and recognize faces in images and videos.

Table of Contents


Overview

This project leverages various face detection and recognition techniques to identify individuals from images or video streams. The core of the project is powered by pretrained models like dlib_face_recognition_resnet_model_v1.dat for face recognition and res10_300x300_ssd_iter_140000.caffemodel for face detection.

The project provides scripts for:

  • Detecting faces from images and videos.
  • Recognizing faces by comparing them to a known dataset.
  • Real-time face detection in live camera feeds.

Features

  • Face Detection: Identify human faces in static images or videos.
  • Face Recognition: Compare detected faces to a database of known faces.
  • Model Integration: Pretrained models for accurate face detection and recognition.
  • Video Support: Face detection from video files and live streams.
  • Easy Customization: Easily extendable to add new models or adapt to custom datasets.

Project Structure

The project is organized as follows:

face-recognition/
├── bin/                            # Executable binaries
│   ├── FaceDetectionLite
│   ├── face_recognition
│   └── FaceRecognition[1-3]
├── data/
│   ├── credentials.csv             # User credentials for face recognition
│   ├── faces/                      # Dataset of faces for recognition
│   │   ├── *.jpg                   # Face image files (e.g. aman.jpg, amit.jpg)
│   └── README.md                   # Data documentation
├── logs/
│   └── package-lock.json           # Logs generated by npm (if applicable)
├── models/                         # Pretrained face detection and recognition models
│   ├── deploy.prototxt.txt
│   ├── dlib_face_recognition_resnet_model_v1.dat
│   ├── res10_300x300_ssd_iter_140000.caffemodel
│   ├── lbpcascade_frontalface.xml
│   └── shape_predictor_68_face_landmarks.dat
├── src/                            # Source code for detection and recognition
│   ├── *.cpp                       # C++ source files
│   ├── *.py                        # Python scripts
│   └── FaceDetection.cpp           # C++ face detection logic
├── tests/                          # Test images and videos
│   ├── test.mp4                    # Test video file
│   └── test.png                    # Test image file
├── move.sh                         # Shell script to organize files
└── requirements.txt                # Python dependencies

Requirements

Ensure the following dependencies are installed:

  • Python 3.x
  • OpenCV
  • Dlib
  • CMake (for building dlib)
  • numpy

For Python dependencies, refer to the requirements.txt file.

Installation

  1. Clone the repository:

    git clone https://github.com/username/face-recognition.git
    cd face-recognition
  2. Install required Python libraries:

    pip install -r requirements.txt
  3. Set up dlib (if not already installed):

    pip install dlib
  4. Download Pretrained Models:

    Ensure the required models are present in the models/ directory:

Usage

1. Detect Faces from an Image

Use the face1.py script to detect faces in an image:

python src/face1.py --input ./data/faces/aman.jpg

2. Real-Time Face Recognition with Webcam

You can run real-time face recognition using a webcam by running:

python src/video1.py

3. Detect Faces from a Video

Use the video1.py script to detect faces from a video file:

python src/video1.py --input ./tests/test.mp4

4. Run the C++ Face Detection:

If you prefer using C++, you can compile and run the C++ source:

g++ src/FaceDetection.cpp -o FaceDetectionLite -lopencv_core -lopencv_imgproc -lopencv_highgui -lopencv_objdetect
./FaceDetectionLite ./data/faces/aman.jpg

Models

Pretrained Models

  • Face Recognition Model: dlib_face_recognition_resnet_model_v1.dat
  • Face Detection Model: res10_300x300_ssd_iter_140000.caffemodel
  • Haar Cascade Model: lbpcascade_frontalface.xml

Model Download

If you do not have the models, you can download them from the following sources:

Tests

Test images and videos are provided in the tests/ folder. You can use them to verify the accuracy of the face detection and recognition scripts.

Run Test Script

Run the Python test script:

python src/face2.py --input ./tests/test.png

Contributing

We welcome contributions to this project! To contribute:

  1. Fork the repository.
  2. Create a new feature branch (git checkout -b feature-branch).
  3. Commit your changes (git commit -m "Added new feature").
  4. Push the branch (git push origin feature-branch).
  5. Create a Pull Request.

Issues

If you encounter any issues, feel free to open a new issue on the repository.

License

This project is licensed under the MIT License - see the LICENSE file for details.


About

Face Recognition code to detect faces on live cameras implemented using OpenCV and Dlib.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published