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

512Numbers in each face fingerprint; the photo itself is not what is stored
137 msTo find a face on the processor with four threads, down from 454 ms
75%Of plate numbers read right before any correction (111 of 147)
0Graphics cards and outside AI services; everything runs locally

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.

CamerasHikvision, across three branches and the inspection lanes
Recorders (NVR)Record and share pictures over ISAPI and video over RTSP
ServerFace Locator and Plate Assist, ONNX models and SQLite
BrowserDashboard, entrance kiosk and a page per 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.

1

Snapshot

A JPEG from the camera over ISAPI, with digest sign-in.

2

Prepare

Decoded with OpenCV and scaled down to about 900 pixels.

3

Detect

The det_10g model returns a box and five key points: eyes, nose and mouth corners.

4

Fingerprint

The w600k_r50 model turns the face into a normalised vector of 512 numbers.

5

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.
Branches and cameras. Three branches, three cameras each, with a switch, edit and delete per camera.
Attendance report. First check-in, last check-out and hours per day, with a button that opens the entrance kiosk.

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 recordSeen nowResult
None, or a check-outAny branchcheck-in
Check-in, same branchSame branchcheck-out
Check-in, other branchDifferent branchnew check-in
90 sCooldown: repeat sightings inside it are ignored.
120 sThe shortest gap between check-in and check-out at the same branch.
16 hAfter this, an old check-in is treated as a fresh one.

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.

CameraLive RTSP video, straight from the lane camera
Video threadGrabs every frame, decodes about one a second
Lane threadFinds the plate, reads it and votes
StorageSQLite events and pictures of each one
Lane pagePolls the state and shows the suggestion

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.

1

Find the plate

yolo-v9-t-640, confidence 0.5 or more, at least 28 pixels wide.

2

Layout

Wider than 1.8 to 1 means one row; otherwise two rows.

3

Read the number

cct-s-v1 reads four crops and votes, up to five digits.

4

Emirate

A red square found by colour means Abu Dhabi, and its number takes the letter's place.

5

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.
Numbers read right
75%
Abu Dhabi square
auto
Letters, generated
97%
Letters, real plates
≤41%

Face Locator performance work

ChangeEffect
Four inference threads, no busy waitingEach pass is faster and the machine is almost idle between passes
Load only the detection and recognition modelsMemory down from 1.1 GB to 0.78 GB
Match with one matrix product, not a Python loopStays fast as the staff list grows
SQLite in WAL modeReaders never wait for a write
Write a healthy camera's status once a minuteFar 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.

DecisionWhyWhen it grows
SQLiteOne server, few writes, and WAL handles concurrencyPostgreSQL with several servers
No front-end frameworkDeploying is editing a file and restartingReact or Svelte if the UI grows
Fingerprints as JSON in SQLiteScanning a few thousand vectors takes under 1 msFAISS or pgvector at 10,000 staff
Inference on the processorEnough once tunedA mid-range graphics card
JPEG snapshots for facesSimpler, and enough for the kioskDecode RTSP video for smoother capture

The two systems side by side

Face LocatorPlate Assist
InputJPEG snapshots over ISAPIRTSP video per lane
ModelsInsightFace, YOLOv8n, TesseractYOLOv9, OCR models, kNN
StorageSQLite, 11 tablesSQLite, one events table
InterfaceJinja2 pages, plain JavaScript, MJPEGA plain JavaScript page per lane
Runningsystemd on Ubuntu, plus a Windows packageUvicorn on the test machine

Shared by both: Python, FastAPI, SQLite and ONNX models on the processor, with no picture sent to an outside service.