Parking Space Counter
π Overview
Analyse a car park's surveillance video in real time: pre-mark each parking bay, check frame by frame whether a car occupies it, and report the number of free spaces with colour-coded overlays.
The core idea is the classic 'mark the regions first, then decide occupancy': store each bay's coordinates and judge occupancy from pixel statistics (whether a large area of car pixels sits inside) or a small model.
π§° What you need
- Computer (video can be processed offline)
- A video or image sequence of a car park
- Python 3.7+ environment
- pip install: opencv-python, numpy
π§ Step by step
Get your source material
Prepare a car park surveillance video
Find a frame with no cars in it to use for marking the bays
Mark the parking bays
Draw each bay as a polygon on the empty frame
Save every bay's vertex coordinates to a list or file
Read frames and judge occupancy
Read the video frame by frame
Count the 'car-like' pixels inside each bay region
Set the occupancy threshold
The pixel counts differ clearly between an empty and an occupied bay
Put the threshold in the middle to reduce misjudgements
Visualise the output
Draw free bays in green and occupied ones in red
Show the free-space count at the top of the frame
Refine and extend
Smooth the threshold over several frames to stop it flickering
You can also track how long each bay stays occupied for parking management
π‘ Tips
- Marking accuracy decides everything - the polygon vertices must follow the bay boundaries
- Using edge or motion pixels inside the bay resists lighting changes better than raw colour
- A fixed camera position gives the best results; stabilise the video first if the image shakes