A Parking Monitor
And a mistake worth seeing.
The farm shop has six parking spaces, and customers keep complaining that they can't find a space. A camera on the roof could show which ones are free. It's a fixed camera, and the spaces never move. So this looks like a very easy job for background subtraction. Let's try it, and see what happens.

- Six parking spaces
- A fixed camera
- This looks easy
Empty against now
We keep one picture of the empty car park. For each space, we compare the current image with that empty picture, and measure the average difference. In our scene, spaces two, three, and five have cars in them. Run it. Spaces two and three are correctly marked as taken. But look at space five. It's marked as free, with a gap of only five. The answer's wrong! Why? That car happens to be almost the same grey as the road. So the difference is tiny. Comparing brightness can't see a grey car on grey tarmac. That's a real failure, and every real parking system has to deal with it.
import cv2
import numpy as np
rng = np.random.default_rng(0)
empty = np.full((200, 600), 110, np.uint8)
slots = [(20 + i * 95, 40, 80, 120) for i in range(6)]
now = empty.copy()
for i, (x, y, w, h) in enumerate(slots):
if i in (1, 2, 4):
cv2.rectangle(now, (x + 8, y + 10), (x + w - 8, y + h - 10), int(rng.integers(30, 200)), -1)
now = cv2.add(now, rng.normal(0, 4, now.shape).clip(0, 20).astype(np.uint8))
for i, (x, y, w, h) in enumerate(slots):
gap = cv2.absdiff(now[y:y + h, x:x + w], empty[y:y + h, x:x + w]).mean()
print(f"Space {i + 1}: {'taken' if gap > 12 else 'free'} ({gap:.0f})")Space 1: free (1) Space 2: taken (45) Space 3: taken (20) Space 4: free (1) Space 5: free (5) Space 6: free (1)
Fixing it
How do we fix that? Look at edges as well as brightness, as a car has outlines, even if it's the same colour. Train a small classifier on crops of each space, which is what most real systems do. Combine several frames. And test in all conditions, including rain, night, and snow. A method that worked on your test image will meet a grey car in its first hour.
Summary
A simple test can hide an obvious failure. Next, how to summarise an image's colours.
Key takeaways- Compare with an empty scene
- Same colour defeats it
- Test tough cases early