Inspiration
Last year a 13 year old child drowned in the swimming pool of my housing society.
We have guards at the gates and security cameras all over the society, including at the pool. But nobody watches those screens 24x7. The cameras record everything, a guard sits in front of a wall of small tiles, and the footage only gets opened after something has already gone wrong.
Most Indian societies work like this. The gate register is a notebook, cabs and delivery bikes come and go all day, and nobody really knows who is inside.
I wanted the cameras a society already has to actually watch.
What it does
Pehra (पहरा, "the watch") is an AI control room for the CCTV a housing society already has.
- Plug in the cameras you have: CCTV and recorders, a small bridge for recorders behind a router, or any phone or laptop.
- Say what to watch in plain words, like "someone in the water after pool hours" or "gate left open after 11 PM". Before you save, Pehra shows what it will watch, what it can't, and how often it would have fired yesterday.
- OpenCV watches every camera live. It finds people and vehicles, tracks them, checks zones and lines, reads number plates at the gate, recognises staff who agreed to be enrolled, and notices when a camera is covered, turned or blurred.
- When a watch fires, an AI agent takes a closer look with OpenCV tools before it decides.
- The guards' Telegram group gets a graded alert with a still picture, faces blurred, and Acknowledge and False alarm buttons. Critical alerts go out at once.
- It also keeps a gate log of every vehicle and a register of staff arrivals.
How we built it
- OpenCV 5 does all the seeing. YOLOX on
cv2.dnnfor people and vehicles, a Kalman filter tracker, MOG2 to skip still scenes, CLAHE for night, YuNet and SFace for faces, LPD YuNet and PP OCR for plates, ORB with MAGSAC for camera health, and DIS optical flow to spot a body that stops moving in moving water. On a phone, OpenCV.js blurs faces before a picture ever leaves the device. - Watches are not hardcoded. The AI turns your sentence into a few simple signals, once. A rule engine checks those signals on every frame, so a new kind of watch is just data, not new code.
- The agent checks, it doesn't watch. It only sees a few stills of a flagged moment, never the video. At each step it can ask OpenCV to zoom in, brighten, measure motion or read a person's pose over time, and what comes back decides its next step.
- The stack: Python with FastAPI, a React web app, and a Telegram bot. For AWS it ships as one CloudFormation stack: a Graviton instance with COOL (OpenCV built for Arm), S3 for clips, Bedrock for the AI, Parameter Store, CloudWatch and SNS. Anyone can also self host it with Docker.
Challenges we ran into
- Making it generic. My first version had a hand written check for every event. I threw that away for plain words compiled into signals, so a society can watch for anything.
- Protecting kids without ever processing kids. Word lists are not enough: people write "a 5 y/o", "मुलगा" or "a k-i-d". The guard ended up with several layers: words, number patterns, a meaning check using an image and text model, and a final check on the AI's own sentences.
- Trackers break at low frame rates. At 1 frame a second, people crossing a line were missed every single time. Fixing the tracker took that from 0% to 83%.
- CPU on old hardware. Running the detector only when something moves, and only looking closer at what a watch needs, took 8 busy cameras from 0.12 to 0.47 frames a second each with a "looks like" watch, and 2.1 without one, on a 2013 server.
- Pools seen from straight above. The small detector misses many swimmers in a top down view. It is the next thing to fix.
Accomplishments that we're proud of
- Faces stay private. Faces are recognised only for adult staff who agreed, and only on entry cameras. Telegram gets stills with faces blurred, and nobody can search the footage with a photo of someone's face.
- A real agent loop. What OpenCV finds changes what the agent does next, and every step is stored and shown on the incident page.
- Honest numbers. I labelled OpenCV's Plaza clip by hand. Across all watches at 2 frames a second Pehra gets 86% precision and 73% recall, and the first miss and first false alarm of every watch are saved as pictures in the repo.
- Anyone can try it. The live demo gives you a private sandbox society, and you can add your own phone as a camera in a few seconds. Over 1,300 automated tests cover it.
What we learned
- OpenCV 5 goes much further than I expected. Deep learning models, face detection and recognition, optical flow and robust homography all live in one library, and the same face detector runs in the browser.
- An AI is most useful when it checks, not when it watches. Letting OpenCV do the watching keeps Pehra fast, cheap and private, and the agent only spends time on real moments.
- Privacy rules are product decisions.
What's next for Pehra
- A stronger detector for pools seen from straight above.
- Pilots with a few societies, starting with my own.
Built With
- amazon-bedrock
- amazon-cloudwatch
- amazon-ec2
- amazon-sns
- amazon-web-services
- aws-cloudformation
- aws-graviton
- cloudflare
- docker
- fastapi
- ffmpeg
- mediapipe
- numpy
- onnx-runtime
- opencv
- openrouter
- playwright
- python
- react
- sqlite
- telegram
- typescript
- vite
- websockets
Log in or sign up for Devpost to join the conversation.