He whipped up a script in Python and OpenCV to automate the counting. The script measures laps by setting two zones on the track. When the train enters the first zone, the counter is armed.