I am attempting to count the number of cars in traffic cameras. This is an obvious problem, and it’s been well-solved, assuming sufficient quality and resolution imagery. But for this use case I have 320×200 cameras, so … there just aren’t enough pixels for the standard algorithms to work well.
So instead, I’m comparing the image against a baseline “no cars” image and counting the number of different pixels. As recommended in other posts, I’m preprocessing by converting color to grayscale and adding Gaussian blur to improve the matching. This works ok, as long as the baseline image is under similar lighting conditions as the captured image, e.g. both under bright sunlight. I’m getting two special cases that I’d like to solve for, though — one is darkness, the other is the combination “dark and also rainy.”
In darkness, the streetlights illuminate the pavement differently than in daylight, so even though there’s enough light to see cars (or not), the pre-processing makes the pavement sufficiently different “color” that I’m getting a few pixels difference, and it’s counting that as cars. If it’s both dark and rainy, then the road becomes reflective, which plays havoc with the results. Now I’m getting reflections from streetlights, traffic lights, etc. on the road surface.
My best ideas so far:
- Totally do something radical with pre-processing to … not sure. I was reading about morphology opening as a way to reduce noise — maybe that’s a good path? Maybe some kind of thresholding before I do the color-to-bw / blur? I like that this approach tries to use a single baseline image to compare against, so it’s the algorithm getting more complex to adapt to a broader dataset. But I have no idea how to preprocess better.
- Get baseline daylight / dark / dark and rainy images. Then produce a histogram from a part of the image (say, trees / buildings, not traffic) and compare it to the options for baseline. Use the baseline where the sampled histogram most closely matches. Intellectually, it’s probably an adequate solution, but it seems like brute force. There’s no elegance here.
Is there a reasonably elegant solution to this problem?
Here is on such image — dark but not rainy
Another image — dark and rainy
Daniel McMath is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.