This is a mini project implementing InsightFace for face recognition using FastAPI and PostgreSQL.
- 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
- Clone the repository:
git clone <repo_url>
cd faceRecognition_Project- Create a virtual environment:
python -m venv .venv
.venv/Scripts/activate- Install dependencies:
pip install --upgrade pip
pip install -r requirements.txt- Create folder for reference images:
mkdir -p resources/references- Ensure PostgreSQL is running and create the database:
CREATE DATABASE facerec_db;Update the database connection in app.py:
conn = psycopg2.connect(
host="localhost",
database="facerec_db",
user="postgres",
password="password"
)python -m uvicorn app:app --reload --workers 1Server will run at: http://127.0.0.1:8000
Recommended to open: http://127.0.0.1:8000/docs
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"
}POST /api/face/recognize
Form-data:
file: image file (.jpg/.png)
Response:
{
"user_id": 1,
"name": "Alice",
"distance": 0.3456,
"status": "Same Person"
}GET /api/face
Response:
{
"faces": [
{
"user_id": 1,
"name": "Alice",
"face_id": 3,
"image_path": "resources/references/xxxx.jpg"
}
]
}DELETE /api/face/{face_id}
Response:
{
"message": "Face 3 deleted successfully"
}| Field | Type | Description |
|---|---|---|
file |
file |
Required. jpg/jpeg/png |