Skip to content
MechStudents2029Public

About

Always-on room camera that recognizes enrolled faces (YuNet + SFace) and logs attendance sessions automatically. Doubles as a data pipeline for robotic perception.

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Repository files navigation

FaceClock Room HQ

Always-on room camera that recognizes enrolled faces, shows who’s in the room now, and logs enter/leave attendance sessions automatically. No punch buttons.

Walk in → seen → named → on the board → session logged.

Live demo

Try it here: https://faceclock.duckdns.org/

Highlights

  • Real-time face recognition (YuNet detector + SFace embeddings) and presence tracking
  • Automatic attendance sessions: people are marked present and then moved to left after a configurable grace window
  • Privacy-first: v1 stores face embeddings and event metadata only (no raw images/video persisted)
  • Admin enroll flow secured with a JWT token

Architecture (high level)

flowchart LR
  Browser[Browser camera (getUserMedia)] -->|HTTPS| Caddy[Caddy TLS + reverse proxy]
  Caddy --> Nginx[nginx: serve SPA + proxy /api]
  Nginx --> FastAPI[FastAPI (/observe, /room, /events, /sessions)]
  FastAPI --> Postgres[(Postgres DB)]
  FastAPI --> CV[OpenCV YuNet + SFace: detect -> embed -> cosine match]
Loading

Resume-ready feature flow

  1. Browser captures a frame
  2. Backend detects faces and matches against stored embeddings
  3. Presence/session state is updated in the database
  4. UI shows who is currently present and the activity history

Privacy

v1 stores face embeddings + event metadata only. Raw face JPEGs / video are not persisted.

Stack

Tech stack badges

  • React 19 + React Router 7
  • TypeScript
  • Vite 8
  • FastAPI (Python)
  • OpenCV (YuNet + SFace)
  • Postgres (SQLite for tests)
  • Docker Compose
  • AWS EC2
  • Caddy (TLS / reverse proxy)

Stack overview

Layer What it does
Browser Captures camera frames + renders UI overlay
Caddy HTTPS termination + routing
nginx / SPA Serves the frontend + proxies /api
FastAPI Receives frames (/observe), runs CV, updates presence
Postgres Stores people, embeddings, presence, events/sessions
  • Frontend: React + Vite + TypeScript
  • Backend: FastAPI + OpenCV (YuNet + SFace)
  • DB: Postgres (SQLite for tests)
  • Ship: Docker Compose + GitHub Actions

Quick start (dev)

1. Database

docker compose up db -d

2. Backend

cd backend
python -m venv .venv
# Windows: .venv\Scripts\activate
source .venv/bin/activate
pip install -r requirements.txt
cp .env.example .env
uvicorn app.main:app --reload --port 8000

3. Frontend

cd frontend
cp .env.example .env
npm install
npm run dev

Open http://localhost:5173

  • Kiosk — start the room camera (continuous observe)
  • Room — live who’s present
  • History — events + attendance sessions
  • Enroll — admin login (default password Adam@246) then save a face

Docker (full stack)

docker compose up --build

Deployment (AWS EC2)

This project is deployed with:

  • EC2 instance running Docker Compose (web + FastAPI + Postgres)
  • Caddy on ports 80/443 using a free DNS name (duckdns.org) and Let’s Encrypt certificates

In production the frontend talks to the API on the same origin using /api, which avoids mixed-content and CORS headaches.

Config (env)

Variable Default Meaning
DATABASE_URL local Postgres URL SQLAlchemy URL
GRACE_WINDOW_SECONDS 90 Seconds without sightings before “left”
MATCH_THRESHOLD 0.363 Cosine match cutoff
UNKNOWN_THROTTLE_SECONDS 30 Min gap between unknown events
CORS_ORIGINS localhost Vite Comma-separated origins
ADMIN_PASSWORD Adam@246 Enroll login
JWT_SECRET dev secret Sign admin tokens
ROI_X/Y/W/H full frame Doorway region as 0–1 fractions
VITE_API_URL http://localhost:8000 Frontend API base
VITE_SCAN_INTERVAL_MS 1500 Kiosk observe interval

API sketch

  • POST /observe — camera frame → sightings + room snapshot
  • POST /auth/login — admin JWT
  • POST /enroll — admin; name + face image
  • GET /room — who’s present
  • GET /events — activity feed
  • GET /sessions — attendance sessions
  • POST /people/{id}/deactivate — admin soft-delete

How the CV pipeline works

On each observed frame, the backend:

  1. Detects faces in the image (OpenCV YuNet)
  2. Aligns crops and computes face embeddings (OpenCV SFace / ONNX)
  3. Compares each embedding to stored embeddings using cosine similarity
  4. If the similarity is above MATCH_THRESHOLD, the person is marked present
  5. A grace-window sweep closes sessions and marks people as left after GRACE_WINDOW_SECONDS seconds without sightings

Tests

cd backend
pytest -q

Presence transitions (enter → present → left after grace), auth gates, and ROI filtering are covered without a physical webcam.

Architecture notes

  • Multi-face frames: every face in the image is recognized and can update presence.
  • Optional doorway ROI ignores faces whose center falls outside the configured rectangle.
  • Attendance sessions open on entered and close when grace-window sweep emits left.

Screenshots

Add 1-2 screenshots or a short GIF here (ideally: kiosk view + room roster).

About

Always-on room camera that recognizes enrolled faces (YuNet + SFace) and logs attendance sessions automatically. Doubles as a data pipeline for robotic perception.

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages