Alright, let me tell you about this people counting project I put together. It wasn’t anything super fancy, but it involved getting a counter working and then figuring out how to check the numbers on my phone.
Getting the itch
It started because I help manage a small community space, and we sometimes needed a rough idea of how many people were coming in and out for certain events. Doing manual clicks felt old-school, and I had a Raspberry Pi lying around gathering dust. So, I thought, why not try to automate this a bit? Gave me a good excuse to tinker.
Figuring out the counting part
First things first, I needed eyes. I grabbed an old USB webcam I had in a drawer and plugged it into the Pi. Simple enough. Then came the tricky part: actually counting people. I installed OpenCV on the Pi, which is like a toolkit for computer vision stuff. My first attempts were pretty basic. I tried just detecting movement, but that counted everything – shadows, doors opening, you name it. Not useful.
Then I looked into actual people detection. Tried some built-in methods in OpenCV. It was better, but still kinda flaky. Lighting changes messed it up badly. Sometimes it counted the same person twice if they paused, or missed them completely if they moved too fast. It took a lot of fiddling around, tweaking settings, trying different detection models I found online. I finally settled on one that seemed okay-ish for my simple indoor setup, but honestly, it was far from perfect. Accuracy was a real challenge.
Just detecting wasn’t enough, though. I needed to know if they were coming in or going out. So, I drew a virtual line across the middle of the camera view in my code. The logic was: if a detected person crosses this line from top-to-bottom, increment the ‘in’ count. If they cross bottom-to-top, increment ‘out’. Getting this tracking and line-crossing logic right took ages. Lots of trial and error, watching the video feed, and seeing why the count was going wrong.
Making it mobile
Okay, so I had a counter running on the Pi, displaying numbers in a terminal window. But I wasn’t always near the Pi, especially during an event. I wanted to check the count easily from my pocket. A mobile app seemed like the way to go.
Now, how to get the count from the Pi to my phone? I needed some kind of connection. I decided to set up a really basic web server on the Raspberry Pi using Python and Flask. It’s pretty straightforward. I made one simple web address (an endpoint) on the Pi. When my phone’s app would ask for this address, the Pi server would just send back the latest people count. I didn’t bother with a database or anything complex at first; the script just kept the count in memory and updated a simple text file now and then.
Building the app
For the mobile app, I wanted something quick and dirty. I’m not a pro Android developer, so I used one of those simple app builder tools – I think it was MIT App Inventor back then, or something similar. It’s block-based, makes things easier. All the app needed was:
- A button to refresh the count.
- A display area to show the number.
- Code to connect to the Pi’s web server address over the local Wi-Fi and grab the count.
It was barebones, really. No fancy graphics, just the number.
Putting it all together (and the problems)
So, I got the Pi connected to the venue’s Wi-Fi. Started the people counting script and the little Flask web server on it. Installed the simple app I built onto my Android phone. Took a deep breath and… it kinda worked! Sometimes.
Oh, there were issues. The Wi-Fi there wasn’t the best, so sometimes the app couldn’t reach the Pi. The counting accuracy, like I said, was hit-or-miss depending on how crowded it got or if the lighting changed suddenly. Sometimes the Python script on the Pi would just crash for no obvious reason, and I’d have to restart it. The app itself was super basic and occasionally froze.
What I learned
It wasn’t a commercial-grade system by any means, but building this thing taught me quite a bit.
- Computer vision is harder than it looks, especially with cheap hardware and changing environments.
- Getting different devices (Pi and phone) talking to each other over a network involves steps I hadn’t done before, like setting up that mini web server.
- Even a simple app takes time to get right.
It was a fun project, though. It did give us a rough estimate during events, which was better than nothing. If I were to do it again, I’d probably invest in a better camera, maybe use a more powerful detection method, and definitely build a more robust way for the Pi and app to communicate, perhaps using something like MQTT instead of a basic web request. But for a DIY job with spare parts, I was pretty chuffed I got it working at all.