filmov
tv
I used Python to Measure Traffic Flow in Cities: Skylines
Показать описание
I made a script in Python that detects, tracks and counts vehicles coming across an intersection. This demo is with a Cities: Skylines recording but it can work for IRL stream as well. I plan to use it to compare different intersection designs and do head-to-head battles between interchange types. At this stage the script is not in a state where I feel confident enough to share it. Once I make it more user-friendly I’ll definitely consider it.
This is NOT A MOD for Cities: Skylines, but a Python program that takes a video file as input. I don’t have the knowledge to make it into a mod (and there are probably better native ways to track traffic). However, if you think it there is a way to do it, please let me know :)
In the center you can see the foreground detection at work. It relies on the OpenCV library. Subtract the average background from each frame and apply a threshold, and you get the moving vehicles as white blobs. This step involves a lot of filtering and parameters, hence why it is not user-friendly just yet.
Using the motion vectors (in light blue), we can predict and track each individual vehicle position within the blue square. The throughput is defined as the number of vehicles exiting that blue square per unit of time. The live throughput in the graph is based on a 10s EMA, it’s also the metric used for the “max throughput” in the summary. The delay is the time at vehicle stays within the blue square.
The roundabout used in this demo is nothing much, just a highway circle with some TMPE tweaks, not optimized in any way. The traffic is generated by 3 equally sized “cities”, and held up by a traffic light to create a constant flow rate. In theory all movements should have the same flow, however you can see vehicles piling up in the two left lanes, that’s why I marked these movements as saturated. In these conditions the right-turns still have some unused capacity, that's why they make up for more than a third of the total.
Let me know in the comments if you have some questions or suggestions. For instance, which intersections you would like me to compare first?
This is NOT A MOD for Cities: Skylines, but a Python program that takes a video file as input. I don’t have the knowledge to make it into a mod (and there are probably better native ways to track traffic). However, if you think it there is a way to do it, please let me know :)
In the center you can see the foreground detection at work. It relies on the OpenCV library. Subtract the average background from each frame and apply a threshold, and you get the moving vehicles as white blobs. This step involves a lot of filtering and parameters, hence why it is not user-friendly just yet.
Using the motion vectors (in light blue), we can predict and track each individual vehicle position within the blue square. The throughput is defined as the number of vehicles exiting that blue square per unit of time. The live throughput in the graph is based on a 10s EMA, it’s also the metric used for the “max throughput” in the summary. The delay is the time at vehicle stays within the blue square.
The roundabout used in this demo is nothing much, just a highway circle with some TMPE tweaks, not optimized in any way. The traffic is generated by 3 equally sized “cities”, and held up by a traffic light to create a constant flow rate. In theory all movements should have the same flow, however you can see vehicles piling up in the two left lanes, that’s why I marked these movements as saturated. In these conditions the right-turns still have some unused capacity, that's why they make up for more than a third of the total.
Let me know in the comments if you have some questions or suggestions. For instance, which intersections you would like me to compare first?
Комментарии