cat ~/projects/cv-people-counter.md

CV People Counter

Webcams count people at every door, and when a flood, fire or earthquake hits, exit signs send everyone to the nearest safe exit.

status
shipped
when
Oct 23 – 25, 2026
where
Disaster-response makeathon
team
Team Dragnipur
stack
#python#yolo11#opencv#fastapi#networkx#sqlite#websockets#arduino
The dashboard during a flood drill: a two-floor building map with a live count in every room, the flooded ground-floor exits crossed out and arrows sending people upstairs.

In a flood, fire or earthquake, two questions matter: who is still inside, and which way is safe right now? Responders rely on sign-in sheets and roll calls, and static exit signs point to the nearest exit even when it’s under water or packed.

CV People Counter answers both. A webcam above each door counts people walking in and out, and a server keeps a live count for every room, floor and building. When a hazard is reported, by staff, a drill button or a sensor, it works out the nearest safe exit for every room. Any screen showing the exit-sign page shows the route, and changes the moment the route does.

An exit sign during a flood: a large arrow and GO UPSTAIRS, with the route to the Room 202 refuge underneath.

How it works

The system in three columns: a webcam and laptop at each door, plus an offline queue and sensors; the server with occupancy, routing, hazards and SQLite; the dashboard and exit signs people see.

  • At the door, a laptop runs a YOLO11 pose model and a tracker on the webcam. When a person’s head crosses the door line, it sends one event: which door, which way, and when. Video never leaves the laptop.
  • Nothing is lost offline. Each event goes into a local SQLite queue before it’s sent, so counting carries on when the Wi-Fi drops and the backlog arrives later. Every event has its own id, so a retry is never counted twice, and late events are replayed in time order, giving the same counts as if they had arrived on time.
  • The server (FastAPI) keeps occupancy per room, floor and building. Counts never go below zero; a room that would is flagged as drifting, so staff can recount it.
  • Routing is a shortest path over the building’s map of rooms and doors (Dijkstra, with NetworkX). A door costs more the more crowded the room behind it is, and a room with a hazard is all but closed. If every exit is blocked, people are sent up to a refuge floor instead; if nothing is safe, the sign says to shelter in place.
  • Sensors: an MPU-6050 accelerometer on an Arduino detects shaking with an STA/LTA trigger (the short-term average of the motion against the long-term one), and thresholds turn water, gas and temperature readings into hazards. In an earthquake the signs say DROP · COVER · HOLD ON first and only show routes once the shaking stops.
  • The dashboard and the signs update live over a WebSocket, and the whole building (rooms, doors, exits, capacities) is one JSON file.

Counting heads, not feet

The first version counted the bottom of each person’s box: their feet. In a doorway, the person behind is often hidden, so a pair walking close together counted as one. Counting the head instead, found with pose keypoints, keeps both people visible from a camera mounted high and tilted down.

Side view: a camera above the door tilted about 45° down, and two people walking toward it, both heads in view.

Someone standing in the doorway also used to flip in, out, in. Now there’s a neutral band around the door line, and a person only counts once their head reaches the far side.

The camera’s view: an inside zone and an outside zone with a neutral band between them along the door line. A path that reaches the far zone is counted; one that turns back in the band isn’t.

How well it worked

  • About 95 % counting accuracy in our walk tests under good conditions, including two people walking through overlapping. The misses came from people sprinting through: a runner crosses the line in only a few, often blurred frames at 30 fps.
  • On a laptop with a GTX 1660 Ti, two real webcams (a Logitech Brio 100 and a C270) counted live at the same time at 25 to 27 frames a second each.

Where it could go next

Ideas from the pitch, none of them built: ranking buildings by who needs rescuing first, ESP32 and LoRa radios so it keeps working when the Wi-Fi fails, routes on phones from a QR code in every room, and depth sensors for better counts.