Alright, let’s talk about something I fiddled with recently – setting up a way to count people coming in and out of a shop in real-time. A friend runs a small place, and they were curious about busy times, how many folks actually walk in versus just passing by. Seemed like a neat little project to tackle.

Getting Started – The Idea

First thought, honestly, was just clicking a manual counter. But who wants to do that all day? Plus, they wanted data even when they were busy. So, the idea became finding an automated way. I looked around a bit online, saw some fancy commercial systems, way too expensive for a small shop.

I figured, maybe I could rig something up myself. I had an old webcam lying around and a spare Raspberry Pi. Could I point the camera at the entrance and somehow count people? That felt like the most doable path without spending much cash.

Putting Things Together

So, I grabbed that old USB webcam and the Pi. The first job was figuring out where to put the camera. You want a clear view of the doorway, high enough to see heads coming through but not so high you miss shorter people or kids. I ended up mounting it on a small shelf near the ceiling, pointing down towards the entrance zone.

Getting power up there was a bit of a stretch, needed an extension cord, but managed to tuck it away okay. Connected the webcam to the Pi’s USB port. Got the Pi connected to the shop’s Wi-Fi, that part was easy enough.

The Software Bit – Trying Things Out

Now, the tricky part. How to make the Pi see people and count them? I’m no coding genius, mind you. I started looking into basic motion detection first. Found some simple Python scripts online using a library called OpenCV. The idea was to detect movement within a specific area – the doorway.

Got a basic script running that could spot changes in the video feed. Okay, progress! But just detecting motion wasn’t enough. A bag swinging, a sign moving slightly, even shadows changing would trigger it. It wasn’t counting people.

So, the next step was trying to make it smarter. I defined a line across the doorway in the camera’s view. The script needed to track moving objects (or ‘blobs’ as the simple code saw them) and only count when a blob crossed that line in a specific direction (coming in). This helped filter out people just lingering near the entrance or walking past outside.

  • Challenge 1: Shadows! Sunny days were a nightmare initially. Changing light conditions made the camera think things were moving. Had to adjust sensitivity settings a lot.
  • Challenge 2: People walking close together. Sometimes the camera saw two people as one big blob. Still not perfect on this, but tweaking the blob size detection helped a bit.
  • Challenge 3: Direction. Making sure it only counted ‘ins’ and not ‘outs’ or people just stepping slightly in and back out took some fiddling with the line-crossing logic.

Making it ‘Real-Time’

The goal was real-time monitoring. What I did was pretty basic. The Python script on the Pi kept a running count. Every few seconds, maybe 5 or 10, it would write the current count to a simple text file. Then, I set up another tiny script that just displayed the number from that text file on a cheap, small monitor connected to the same Pi, placed discreetly near the till. It wasn’t instantaneous down-to-the-millisecond, but updating every few seconds felt ‘real-time’ enough for their needs.

How it Ended Up

So, does it work? Yeah, mostly! It’s not 100% accurate. It still misses people sometimes, especially during really busy rushes, and occasionally double-counts if someone pauses right on the line. But it gives a much better picture than just guessing.

What we learned:

  • It provided useful data on peak hours. They could adjust staffing slightly based on actual traffic patterns.
  • It highlighted how many people walk in during certain promotions versus normal days.
  • It was a fun project, lots of trial and error, but satisfying to get something working.
  • Perfection is hard (and maybe unnecessary). Getting 80-90% accuracy with simple tools was good enough for what they needed.

It’s definitely a DIY solution, rough around the edges. But for a low-cost way to get a general sense of foot traffic, it did the job. Took a bit of patience and messing around, but that’s half the fun, right?