Skip to content

This project demonstrates a basic face recognition system using Python, OpenCV, and the face_recognition library.

License

Notifications You must be signed in to change notification settings

LasithaAmarasinghe/Face-Recognition

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

16 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Face-Recognition

Overview

  • This project demonstrates a basic face recognition system using Python, OpenCV, and the face_recognition library.
  • The system can encode known faces from images in a directory, recognize faces in an input image, and label the recognized faces.
  • This repository contains all the codes and resources of this project.

Steps

  • Encoding faces from images stored in a directory.
  • Recognizing and label faces in an input image.
  • Displaying the input image with labeled faces.

Code

You can find the code for this project here.

Technologies/Tools

  • Python 3.10.12
  • OpenCV pip install opencv-python
  • Python packages
    • numpy pip install numpy
    • cmake pip install cmake
    • dlib pip install dlib
    • face_recognition pip install face_recognition

Python OpenCV NumPy cmake dlib face_recognition

Installation

  1. Clone the repository:

    git clone https://github.com/LasithaAmarasinghe/Face-Recognition.git
    cd Face-Recognition
  2. Create and activate a virtual environment (optional but recommended):

    python -m venv venv
    source venv/bin/activate   # On Windows use `venv\Scripts\activate`
  3. Install the required packages:

    pip install -r requirements.txt

Usage

  1. Prepare the Faces Directory:

    • Create a directory named faces in the root of your project.
    • Add images of known faces to the faces directory. Ensure the images are named with the format name.jpg or name.png where name is the label you want to assign to the face.
  2. Run the Face Recognition Script:

    • Place the image you want to test in the root of your project directory and name it test.jpg.

    • Run the script:

      python face_rec.py
  3. Interact with the Display:

    • The script will display the test.jpg image with labeled faces.
    • Press 'q' to close the display window.

Code Explanation

  • get_encoded_faces(): This function scans the faces directory, encodes each face, and stores the encodings in a dictionary.
  • unknown_image_encoded(img): This function encodes an unknown face from a given image file.
  • classify_face(im): This function reads an image, detects faces in it, compares them to the known face encodings, labels the faces, and displays the image with labeled faces.

Results

image results (3)

License

  • This project is licensed under the MIT License. See the LICENSE file for details.

About

This project demonstrates a basic face recognition system using Python, OpenCV, and the face_recognition library.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages