Okay, so I’ve been wanting to get a better handle on how many people are actually coming through my local mall. You know, just for fun, and maybe to see if I can predict when it’s gonna be super crowded. I figured, why not build something myself? It sounded like a cool weekend project, and plus, I could brush up on some tech skills.

The Idea

The basic idea was to create a counter that could accurately track people entering and exiting the mall. I didn’t want anything super fancy, just something reliable. And, I thought it would be neat to have the data displayed somewhere I could easily check it.

Getting Started

First, I needed to figure out how to count people. I thought about a few options:

  • Manual Clicker: Nah, way too old-school, and I’d have to stand there all day.
  • Pressure Mat: Seemed okay, but what if two people stepped on it at the same time?
  • Infrared Beam: This sounded promising! Like those invisible tripwires you see in movies.
  • Computer Vision: Now we’re talking! Using a camera and some clever software to see people.

I ended up going with the computer vision route. It seemed like the most accurate, and I was itching to play around with some image processing.

The Setup

I grabbed an old webcam I had lying around and hooked it up to a Raspberry Pi (a tiny, cheap computer). I positioned the camera above one of the mall entrances, making sure it had a good view of people coming and going.

The Code

This was the fun part! I used Python, because it’s pretty easy to learn and has tons of libraries for image processing. I found a great library called OpenCV, which is basically the go-to for anything computer vision related.

The code basically does this:

  1. Takes the video feed from the camera.
  2. Detects “blobs” (which are hopefully people).
  3. Tracks those blobs as they move.
  4. If a blob crosses a certain line on the screen, it counts as a person entering or exiting.

It took some tweaking to get it right. I had to adjust the sensitivity so it wouldn’t count things like shopping bags or strollers. I also played around with the “blob detection” settings to make sure it was accurately identifying people.

Displaying the Data

I wanted to see the counts in real-time, so I wrote a simple program to display the numbers on a little screen attached to the Raspberry Pi. I also set it up to send the data to a simple website, so I can view the traffic number on the phone when I am not in the mall.

Testing and Tweaking

I spent a good chunk of time just watching the camera feed and the counter, making sure it was working correctly. I noticed a few issues at first:

  • Double Counting: Sometimes, it would count the same person twice if they hesitated at the entrance.
  • Missed Counts: If people walked really close together, it would sometimes only count them as one person.
  • Lighting Changes: Shadows and bright sunlight could sometimes mess with the detection.

I went back to the code and made some adjustments to fix these problems. It involved a lot of trial and error, but eventually, I got it to a point where it was pretty accurate.

The Result

After a weekend of tinkering, I had a working foot traffic counter! It’s not perfect, but it’s surprisingly accurate. I’ve been using it to track the mall’s traffic patterns, and it’s been really interesting to see how the numbers fluctuate throughout the day and week.

It feels so great to build a useful tool by myself!