Case study
Cameras that know faces and plates
Two Python services that turn the company's Hikvision cameras into face recognition and number-plate reading. Both run entirely on the company's own server, on the processor with no graphics card, and no image is ever sent to an outside service.
Wael Hanna · Python, ONNX, OpenCV · Nov 2026
Overview
From the camera to the screen
The company tests and registers vehicles at three branches. Its cameras were already recording; these two systems make them useful in the moment: who is in the building, and which plate just pulled into a lane.
Plate Assist reads the lane cameras directly instead of through the recorder, because the recorder's re-stream arrived damaged.
face locator
Pulls pictures from the cameras, finds faces, turns each into a 512-number fingerprint with InsightFace, and matches it against the staff on file. It records attendance and the last place each person was seen.
plate assist
Reads each lane's live video, finds the plate with YOLOv9, reads it with OCR models, and settles on an answer by voting across several reads. The lane staff confirm or correct it with one key.
Face locator
From a face to a fingerprint
Each camera has its own thread pulling snapshots. Recognition runs in five steps, one picture at a time behind a single lock, with attendance cameras served first, about every 0.9 seconds.
Snapshot
A JPEG from the camera over ISAPI, with digest sign-in.
Prepare
Decoded with OpenCV and scaled down to about 900 pixels.
Detect
The det_10g model returns a box and five key points: eyes, nose and mouth corners.
Fingerprint
The w600k_r50 model turns the face into a normalised vector of 512 numbers.
Match
Cosine similarity against every staff fingerprint in one matrix product; the best match counts above 0.45.
Live status and staff
The dashboard shows the last place each person was seen across all three branches, the match confidence, and how many cameras are connected. It refreshes every five seconds.
- Staff records hold department, phone, plate number and home branch, with filters on every column.
- Each person can have several registered photos; a registration link can be sent over WhatsApp.
- Cameras are added per branch, with their channel and snapshot interval, and attendance cameras are marked apart from monitoring ones.
Attendance
Attendance as a state machine
A camera sees the same person many times a minute. A few clear rules turn those sightings into one check-in and one check-out.
| Last record | Seen now | Result |
|---|---|---|
| None, or a check-out | Any branch | check-in |
| Check-in, same branch | Same branch | check-out |
| Check-in, other branch | Different branch | new check-in |
Modules
Around the core
Smaller pieces that make the system usable day to day.
Entrance kiosk
A full-screen page per branch showing the live camera and checking the status every second.
Self-registration
A signed link valid for 48 hours; the phone guides the person through their photos with MediaPipe.
WhatsApp bridge
A small Node.js process with Baileys sends registration links, talking to the main service only on the local machine.
ZKTeco doors
Opens the door by reproducing the requests of the BioTime system, with a 20-second cooldown.
Recorder monitor
Checks every recorder channel each minute and logs when a camera drops and when it comes back.
Vehicle library
A YOLOv8n model finds the car and Tesseract reads its plate.
Security
Faces are sensitive data
The system holds people's faces, so access is narrow and nothing leaves the building.
A face is stored as numbers
What is matched is a 512-number vector, not a photo. Only event crops are kept as pictures, and nothing is sent to an outside service.
Sessions and passwords
Signed session cookies valid for 12 hours, HTTP-only, with no tokens in the browser. User passwords are hashed with bcrypt; camera passwords are encrypted with Fernet, with the key kept outside the code.
Two roles
Admins see everything. The second role can only reach the employees page and cannot delete anything.
Checked three times
Permissions are enforced by the API (403), by the pages (redirect) and by the menu, so a hidden link is never the only guard.
Plate assist
Reading plates at the lane
At an inspection lane, staff type each car's plate. Plate Assist reads it first and offers the answer, so the staff member confirms with one key or fixes a character.
One thread per lane. The detection rate drops when no car is present, and if the video fails, the lane falls back to camera snapshots.
Find the plate
yolo-v9-t-640, confidence 0.5 or more, at least 28 pixels wide.
Layout
Wider than 1.8 to 1 means one row; otherwise two rows.
Read the number
cct-s-v1 reads four crops and votes, up to five digits.
Emirate
A red square found by colour means Abu Dhabi, and its number takes the letter's place.
Vote
A ten-second window; the reading counts after three that agree.
Look-alikes are fixed: letters that resemble digits, such as O and B, are mapped to 0 and 8 in the number.
A board per lane
Each lane has its own board and log. When the suggested and final plate differ, a person corrected the reading, and that correction is kept.
- "x3" next to a plate means three reads of the same car were merged into one event.
- The top of the page counts confirmed and corrected plates and the share read right.
- Events move from pending to confirmed, edited or dismissed, or expire if the car leaves first.
- Reads join one event when their boxes overlap by more than 0.3, or differ by a single character; repeats within 15 minutes are linked to the first.
Correct it in place
Opening an event shows the full frame with the plate boxed in green, a magnified crop and up to six extra crops to compare.
- Two fields fix the letter and the number; two lists set the plate type and the emirate.
- Corrections are what the emirate and letter readers learn from.
Results
Measured, then improved
Both systems were tuned against real numbers rather than guesses.
Plate reading, honestly
Measured on plates staff corrected, some of them repeats of the same car. Letters are still the weakest part, because a letter is only 8 to 14 pixels tall in the picture.
- The emirate is learned from the plate's top strip with three examples each; after learning it suggests Dubai for 37 cars and Abu Dhabi for 15.
- A small letter-reading network reaches 97% on generated images but 38–41% on real plates, so it is kept out of the live system for now.
Face Locator performance work
| Change | Effect |
|---|---|
| Four inference threads, no busy waiting | Each pass is faster and the machine is almost idle between passes |
| Load only the detection and recognition models | Memory down from 1.1 GB to 0.78 GB |
| Match with one matrix product, not a Python loop | Stays fast as the staff list grows |
| SQLite in WAL mode | Readers never wait for a write |
| Write a healthy camera's status once a minute | Far less disk activity |
Result: about one processor core on average, in short bursts, where two cores had been busy all the time. Finding a face went from about 454 ms on one thread to about 137 ms on four.
Operations
Running it
Deliberately simple to run, and safe to update.
Ubuntu server
A virtual machine with 10 processors, 13 GB of memory and no graphics card. Face Locator and the WhatsApp bridge run as system services, with TLS on the registration page.
Windows package
A camera-monitoring-only build with recognition switched off, started at boot as a scheduled task and reachable only on the local network.
Safe deploys
Changed files are packed and copied, compiled and import-checked, the service restarts, and a health check runs. The database is backed up before every deploy.
Plate Assist settings
Lanes come from one file. Detection runs at one frame a second with a car and half that without, three agreeing reads are required, and a review mode works with no cameras. Recorder credentials come from the environment, never from files, and the service runs at low priority on three cores.
Decisions
Decisions, and when to change them
Each choice fits today's size, with a clear next step if it grows.
| Decision | Why | When it grows |
|---|---|---|
| SQLite | One server, few writes, and WAL handles concurrency | PostgreSQL with several servers |
| No front-end framework | Deploying is editing a file and restarting | React or Svelte if the UI grows |
| Fingerprints as JSON in SQLite | Scanning a few thousand vectors takes under 1 ms | FAISS or pgvector at 10,000 staff |
| Inference on the processor | Enough once tuned | A mid-range graphics card |
| JPEG snapshots for faces | Simpler, and enough for the kiosk | Decode RTSP video for smoother capture |
The two systems side by side
| Face Locator | Plate Assist | |
|---|---|---|
| Input | JPEG snapshots over ISAPI | RTSP video per lane |
| Models | InsightFace, YOLOv8n, Tesseract | YOLOv9, OCR models, kNN |
| Storage | SQLite, 11 tables | SQLite, one events table |
| Interface | Jinja2 pages, plain JavaScript, MJPEG | A plain JavaScript page per lane |
| Running | systemd on Ubuntu, plus a Windows package | Uvicorn on the test machine |
Shared by both: Python, FastAPI, SQLite and ONNX models on the processor, with no picture sent to an outside service.