Once the coordinates of the lights are calculated the set of lights with the largest dimension is chosen from which the light sequence is constructed in the second subfunction.
The traffic light is then continually monitored and the light sequence updated over the entire video.