Okay, so I went to this music festival a while back, and man, it was packed. Like, sardines-in-a-can packed in some areas. People pushing, couldn’t really move, you know the deal. It wasn’t exactly dangerous then, but you could see how it could get bad. Got me thinking, there’s gotta be a better way for organizers to know where the crowds are bunching up, right? Before things get dicey. That’s kinda how this whole people counting thing started for me. Just an idea born out of slightly sweaty, uncomfortable experience, wanting to see if I could rig something up.

First thing, I just started sketching ideas. My first thought was maybe those clicker things people use at doors, but automated? Nah, too simple, doesn’t track flow well. Then maybe pressure pads? Too complex to set up everywhere. So, cameras seemed like the obvious path. I spent some time just digging around, seeing what tech folks were using. Lots of super complex, expensive systems out there, commercial stuff. But I wanted something I could actually put together myself, something more down-to-earth, you know? Something that wouldn’t cost an arm and a leg.

Getting the Gear Together

Alright, hardware time. I needed a camera, obviously. I didn’t splash out on anything fancy. Just grabbed a decent IP camera, the kind you might use for home security. Made sure it was okay with a bit of weather, thinking it might sit under a tent flap or something. The key part was figuring out what would actually process the video feed. My laptop? Too bulky. A full PC? No way. A Raspberry Pi seemed like the perfect fit – small, cheap, and tons of people use them for projects. So, I got myself a Pi 4, snagged a decent-sized SD card for the software, and a portable power bank so I could test it without being tethered to a wall socket. Plus all the usual fiddly bits like cables and a case.

Writing the Code Bit by Bit

This was where I spent most of my time, hunched over the keyboard. I decided to go with Python. Why? Well, honestly, ’cause I already knew it a bit, and more importantly, there are loads of ready-made chunks of code – libraries, they call ’em – that handle the heavy lifting. The big one for this was OpenCV. It’s pretty much the go-to for anything involving looking at images or video with code.

The basic plan was simple enough in my head:

  • Grab a picture (a frame) from the camera feed.
  • Find anything that looks like a person in that picture.
  • Draw an imaginary line on the screen.
  • If a ‘person’ crosses that line, count it.
  • Try figure out which direction they crossed, so you count entries and exits.

Simple plan, yeah? Turned out to be a real headache in practice. Getting the ‘person detection’ bit working reliably was tough. Early on, my system was enthusiastically counting stray dogs, lamp posts, even fast-moving clouds sometimes. It took ages fiddling with the settings, adjusting sensitivity. I tried a few different methods for detecting people. Started with some older, simpler stuff, then eventually moved to using a pre-trained model – I think it was a version of YOLO, which stands for ‘You Only Look Once’. Sounds cool, right? It was better, but still not perfect. Needed a decent amount of processing power, which the little Pi sometimes struggled with when lots was happening on screen.

Then there was the counting logic. Making sure it counted someone crossing the line only once, and figuring out if they were coming or going. More tweaking, more testing, more coffee.

Putting it to the Test (and Failing a Bit)

Once I had something that vaguely worked on my desk, watching recorded videos, it was time for the real world. Which, as always, ruins everything. I didn’t jump straight to a massive festival. Started smaller. Set up the camera looking at my garden gate. Had my partner, my kids, even the confused dog walk back and forth. The results? Let’s just say ‘mixed’. It caught most people, but sometimes it would miss someone walking quickly, or count one person as two if they paused right on the line.

Lighting was a nightmare. A bright sunny day made everything look different to the software compared to a cloudy afternoon. Shadows were the enemy! And forget about night time initially; the basic camera was useless. I tried taking it to a local farmer’s market one weekend (got permission first!). More people, more unpredictable movement. It really highlighted the flaws. Sometimes the count was way off. The Pi definitely started chugging when the market got busy. It was clear I needed to make the code smarter and maybe less demanding.

Making it Suck Less

Okay, back to the code. The testing showed the weak spots.

Accuracy was the main thing. I spent more time tuning the detection model. Found a ‘lite’ version that ran faster on the Pi without sacrificing too much accuracy. Also added some simple logic to ignore detections that were too small or only appeared for a split second – helped cut down on false counts from random objects. I tried to make the line-crossing detection a bit more robust, requiring the ‘person’ to be clearly on both sides of the line before counting.

Performance was the other big issue. I tweaked the code to process fewer frames per second. Instead of trying to analyze every single frame (like 30 per second), maybe just do 5 or 10. For counting people walking, that was often enough, and it eased the load on the poor Raspberry Pi.

I also realized just having a number wasn’t super useful on its own. How does someone see this count? So, I bolted on a really basic web page thing. The Pi would calculate the count and send the number over the local network every minute or so to a simple display I could pull up on my phone or a tablet. Nothing fancy, just the current count, maybe IN and OUT totals. It felt more like a complete ‘system’ then.

So, where did it end up? Honestly, it’s not a commercial-grade product. It wouldn’t handle every situation perfectly. Dense crowds where people are shoulder-to-shoulder are still really hard for this kind of simple setup. Bad lighting is still tricky. But… it worked for its basic goal. In my tests, in reasonably well-lit areas with people moving normally, it could give a pretty decent estimate of how many people passed by. Good enough to give a festival organizer a rough idea if one area was suddenly getting way more foot traffic than another.

The biggest takeaway for me? Building stuff for the messy real world is way different than just coding theory. You hit problems you never expected. But figuring out how to bash the hardware and software into shape, bit by bit, until it actually does the thing you imagined? That’s the fun part. Started as just an idea watching a crowd, ended up with a little box that actually counts people. Pretty neat feeling.