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.
Try it here: https://faceclock.duckdns.org/
- 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
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]
- Browser captures a frame
- Backend detects faces and matches against stored embeddings
- Presence/session state is updated in the database
- UI shows who is currently present and the activity history
v1 stores face embeddings + event metadata only. Raw face JPEGs / video are not persisted.
- 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)
| 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
docker compose up db -dcd 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 8000cd frontend
cp .env.example .env
npm install
npm run dev- 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 compose up --build- Web: http://localhost:8080
- API: http://localhost:8000
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.
| 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 |
POST /observe— camera frame → sightings + room snapshotPOST /auth/login— admin JWTPOST /enroll— admin; name + face imageGET /room— who’s presentGET /events— activity feedGET /sessions— attendance sessionsPOST /people/{id}/deactivate— admin soft-delete
On each observed frame, the backend:
- Detects faces in the image (OpenCV YuNet)
- Aligns crops and computes face embeddings (OpenCV SFace / ONNX)
- Compares each embedding to stored embeddings using cosine similarity
- If the similarity is above
MATCH_THRESHOLD, the person is marked present - A grace-window sweep closes sessions and marks people as left after
GRACE_WINDOW_SECONDSseconds without sightings
cd backend
pytest -qPresence transitions (enter → present → left after grace), auth gates, and ROI filtering are covered without a physical webcam.
- 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
enteredand close when grace-window sweep emitsleft.
Add 1-2 screenshots or a short GIF here (ideally: kiosk view + room roster).