Skip to content

Repository files navigation

Face Recognition - InsightFace

Overview

This is a mini project implementing InsightFace for face recognition using FastAPI and PostgreSQL.


Features

  • Register new users and their face images
  • Detect faces from input images
  • Match faces against the database
  • Store face data in PostgreSQL
  • Delete face data from the database

Tutorial

  1. Clone the repository:
git clone <repo_url>
cd faceRecognition_Project
  1. Create a virtual environment:
python -m venv .venv
.venv/Scripts/activate
  1. Install dependencies:
pip install --upgrade pip
pip install -r requirements.txt
  1. Create folder for reference images:
mkdir -p resources/references
  1. Ensure PostgreSQL is running and create the database:
CREATE DATABASE facerec_db;

Database Configuration

Update the database connection in app.py:

conn = psycopg2.connect(
    host="localhost",
    database="facerec_db",
    user="postgres",
    password="password"
)

Running the Server

python -m uvicorn app:app --reload --workers 1

Server will run at: http://127.0.0.1:8000 Recommended to open: http://127.0.0.1:8000/docs


API Endpoints

1. Register Face

POST /api/face/register

Form-data:

  • file : image file (.jpg / .png)
  • name : string

Response:

{
  "user_id": 1,
  "face_id": 3,
  "name": "Alice",
  "message": "Face registered successfully"
}

2. Recognize Face

POST /api/face/recognize

Form-data:

  • file : image file (.jpg / .png)

Response:

{
  "user_id": 1,
  "name": "Alice",
  "distance": 0.3456,
  "status": "Same Person"
}

3. Get All Faces

GET /api/face

Response:

{
  "faces": [
    {
      "user_id": 1,
      "name": "Alice",
      "face_id": 3,
      "image_path": "resources/references/xxxx.jpg"
    }
  ]
}

4. Delete Face

DELETE /api/face/{face_id}

Response:

{
  "message": "Face 3 deleted successfully"
}

Notes

Field Type Description
file file Required. jpg/jpeg/png

About

Face Recognition API

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages