Professional Documents
Culture Documents
Design_and_Simulation_of_Optimized_Traff
Design_and_Simulation_of_Optimized_Traff
By:
May 2024
APPROVAL SHEET
This engineering design entitled “Design and Simulation of Optimized Traffic Light Control
System Using YOLOv8” by Jan Eliel Bualoy, Golden Dhan Domingo and Ivan Floyd Erer has
been examined and approved by the Panel of Oral Examinees
Winelfred G. Pasamba
Adviser
PANEL OF EXAMINERS
Accepted as partial fulfillment of the requirements for the degree Bachelor of Science in Electronics Engineering
ii
ABSTRACT
light system using YOLOv8 as a computer vision model to address the evolving dynamics
of urban traffic. Leveraging deep learning models such as YOLOv8n for object detection
and image classification, the system aims to improve traffic flow efficiency and safety at
intersections. The study evaluates the performance of the model through rigorous
the model accuracy while classification reached top-1 accuracy 98% on average in different
along with detection model as a hybrid technique to optimize traffic light timing systems.
Safety concerns dictate that on-site implementation is deferred until the system reaches a
38.28% mean %extra green time to 10.81%. Recommendations for further research
emphasize the need for continuous improvement, scalability, and integration of user
continuous refinement and adherence to safety standards, the optimized traffic light system
presents a promising solution to mitigate urban traffic congestion and enhance road safety.
traffic density
iii
ACKNOWLEDGEMENT
We would like to express our deepest gratitude to everyone who made this thesis
First, to our Almighty God for the wisdom, strength, and guidance that has
for his invaluable guidance, encouragement, and expertise that significantly contributed
Our sincere thanks to Engr. Jona Castaño, Engineering Department Chair, Engr.
Elmer Joaquin, Machine Learning Advisor, and Dr. Lorcelie Taclan, External
Consultant, for their insightful feedback and assistance that helped us grow in this
Lastly, we are grateful to our family and friends for their unwavering love,
iv
TABLE OF CONTENTS
CHAPTER 1
THE PROBLEM AND ITS BACKGROUND ..........................................................1
Introduction ..............................................................................................................1
General Objectives ...................................................................................................3
Specific Objectives ..................................................................................................3
Significance of the study ..........................................................................................3
Scope and Limitation ...............................................................................................4
CHAPTER 2
REVIEW OF RELATED LITERATURE ................................................................5
Definition of Terms................................................................................................11
Theoretical Framework: .........................................................................................12
CHAPTER 3
MATERIALS AND METHODOLOGY .................................................................15
MATERIALS
Software Components ......................................................................................15
Transfer Learning Models................................................................................15
Datasets ............................................................................................................17
Electronic Components: ...................................................................................18
METHODOLOGY
I. Traffic Density Model ..................................................................................21
A. Deep Learning Pipeline .........................................................................21
B. Image Classification and Object Detection ...........................................24
C. Inference Processing .............................................................................25
v
II. CCTV System and Traffic Light System with Integrated Optimized System
..........................................................................................................................32
III. Image Detection through Varied Environmental Conditions ....................39
DESIGN CONSTRAINTS ....................................................................................41
CHAPTER 4
RESULTS AND DISCUSSION ................................................................................42
I. YOLOv8 Model Validation Results .............................................................42
II. Optimized Traffic Light Timing .................................................................48
III. Environmental Conditions Performance ....................................................50
CHAPTER 5
CONCLUSION AND RECOMMENDATION .......................................................53
REFERENCES ..................................................................................................................57
APPENDICES ...................................................................................................................60
Appendix A: Initial Draft Review Matrix ....................................................................60
Appendix B: Local Government Cooperation Summary.............................................61
Appendix C: Change Matrix ........................................................................................63
Appendix D: Request Letter for CCTV and Traffic Light Access ..............................65
Appendix E: Traffic Light Lanes Raw Data ................................................................66
Appendix F: Source Code ............................................................................................68
Appendix G: Similarity Index......................................................................................76
Appendix H: Certificate of Technical Editing .............................................................77
CURRICULUM VITAE ....................................................................................................78
LIST OF FIGURES
vi
Figure 9. Logic Level Bi-directional Converter and specifications. ..................................20
Figure 10. Image Classification and Object Detection Deep Learning Pipeline ...............22
Figure 11. Accuracy, Precision and Recall Equations .......................................................22
Figure 12. Sample Precision-Recall Curve ........................................................................23
Figure 13. YOLOv8 Architecture, visualization................................................................24
Figure 14. Sample image classification and sample object detection ................................25
Figure 15a. Model Inference Process Flow. ......................................................................26
Figure 15b. Timer and Variables Initiation Process Flow. ................................................27
Figure 15c. Pedestrian Signal Process Flow. .....................................................................28
Figure 15d. Next Signal Lane Process Flow. .....................................................................30
Figure 15e. Warning Signal Process Flow. ........................................................................31
Figure 16. Block diagram of CCTV system to Traffic Light system . ..............................33
Figure 17a. Traffic Light System Process..........................................................................34
Figure 17b. Automatic Cycle of Traffic Light Process......................................................35
Figure 17c. Manual Cycle of Traffic Light Process. .........................................................36
Figure 18. Miniature Traffic Light system with proposed dimensions. ............................37
Figure 19. Traffic Light Controller and Optimized Actuator schematic. ..........................38
Figure 20. Mean %Extra Green Time formula. .................................................................39
Figure 21. Simulated environmental conditions. ...............................................................39
Figure 22. Object Detection Precision-Recall Curve .........................................................43
Figure 23. Object Detection Validation Results. ...............................................................43
Figure 24. Object Detection Confusion Matrix. ................................................................44
Figure 25. Sample Object Detection Prediction.. ..............................................................45
Figure 26. Image Classification Validation Results. .........................................................46
Figure 27. Image Classification Confusion Matrix............................................................46
Figure 28. Sample Image Classification Prediction. ..........................................................47
Figure 29. Sample validation of different environmental conditions. ...............................52
LIST OF TABLES
Table 1. YOLOv8n Performance .......................................................................................16
Table 2. YOLOv8n-cls Performance .................................................................................17
Table 3. Traffic Light Lanes Average Timing Comparison ..............................................49
Table 4. Validation Performance per Environmental Condition .......................................51
vii
CHAPTER 1
The Philippines is one of the fastest growing countries in Southeast Asia. And with
more industries launching and urbanization expanding, the capital city Metro Manila, is
the eighth worst in the world in hours spent in traffic among cities based on a recent study
congestion problem also costs the country an economic loss of approximately 3.5 billion
pesos (JICA, 2022). Thus, the pursuit for a solution is continuous to alleviate this problem
in the country.
Authority) Road Safety Unit Traffic Operations was upgrading its fixed countdown traffic
lights with advanced traffic signals that operate based on an intersection's volume of
vehicles (CNN Philippines Staff, 2022). This upgrade cost 295 million pesos (Gamil,
2014). Some of the technologies utilized in this project include closed circuit television
cameras (CCTVs) and underground loop detectors. However, many traffic light systems
outside the scope of MMDA are using fixed-timer technology to control traffic lights.
Induction loop detectors are an expensive upgrade; based on the past upgrade of
the MMDA; which focused on the “more green-light time” of a motorist. Though this
system could be reliable and require minimal maintenance, it could only account for an
Most crossings with a traffic light, with or without a vehicle detector, include a
CCTV (Closed Circuit Television), monitored for motorists' safety. These camera systems
1
are regularly monitored but do not contribute to the control of the traffic lights, since most
systems do not have a central control system but use a fixed-timer or a countdown system.
The optimization of these traffic light systems will benefit from the current CCTV
systems installed at traffic light systems using computer vision. Different techniques are
being studied and developed that have led to the use of Computer Vision as a solution to
the traffic congestion problem. One notable research in the Philippines, with the use of
Computer Vision, was a proposal to develop an intelligent traffic light system using
computer vision to measure the traffic density in an intersection regardless of the time of
day (Nodado et al., 2018). This method used a technique called image segmentation. Image
segmentation is a key part of computer vision as it allows you to define features that
Deep Learning using popular object detection techniques such as YOLO (“You
Only Look Once”), are also being studied by counting detections and tracking objects, but
this proved challenging during night scenes when detection criteria are not being met by
the objects needed to be detected (Sharma et al., 2021). Electronic sensor methods such as
a PIR (Passive Infrared) sensor are also considered; the method focuses on motion
detection and density estimations (Agarwal, 2016). With more implementations and
methods studied, most traffic light optimizations are focused on traffic density or through
This study focuses on detecting objects and calculating traffic density through the
utilization of a hybrid image classification and object detection techniques merged into a
2
General Objectives
electronic physical system and a custom model pipeline to be evaluated for different
environmental conditions.
Specific Objectives
1. To develop a traffic density calculator pipeline using YOLOv8 classify and detect
2. Integrate the optimized system with minimal requirements into a traffic light system
prototype and multiple video IP stream inputs to minimize extra green signal time.
3. Evaluate the performance of the proposed traffic light control system through
a. Daytime
b. Night
c. Fog
d. Rain
of tasks. The study will benefit the current traffic light implementation by providing an
3
operation, and maintenance of the traffic light control system. It will utilize existing CCTV
The study is limited by the following as to design and implement the optimized
traffic light control system using a hybrid of image classification and object detection:
1. The design will be a prototype implementation with focus on the workflow and
integration of the Computer Vision system and NOT the overall stability of the
3. The CCTV system will be proxied through video streams instead of a real-time
stream due to security and safety factors. CCTV video will be sourced at a local 4-
4. The system optimization is only applicable during non-peak traffic hours with
which at peak traffic hours the system adapts maximum value based on the local
4
CHAPTER 2
Traffic light control can easily increase complexity in terms of distinct phases to
define, the number of lanes in an intersection, the type of lighting patterns, the light
actuation type, and other overlooked parameters. In this study, the scope and limitation of
the prototype implementation is defined with the focus on simple workflow of the system.
light. Not all intersections are the same in terms of their cycles, timing, and phases. The
study focuses on a cycle with exclusive phasing, which allows only a single lane to flow to
the rest of the lanes. Thus, it does not allow even concurrent phases or phases that can both
have a green time, for example, opposing lanes in a 4-way intersection going left at the
There is another basic concept for timing of model signals that is built on
assumptions that there is a zero initial queue at the start of each phase with a uniform arrival
and departure flow rate. Notice in Figure 1, that after Qs or the queue clears, there is always
an extra effective green time allotted for change of traffic flow rates at every cycle. This
means that when traffic density increases, this cycle fails, and on average, when the queue
is finished, the wasted green light time is up to 25%, thus the need for another control
5
Figure 1. Deterministic Component of Delay Models. Adapted from Rouphail et al.,
1997.
There are three major traffic control strategies used to solve traffic light timing –
fixed-time, actuated and adaptive. The fixed time is the conventional and the most common
way to time traffic lights using a fixed duration for each cycle. Then another is actuated,
which this research seeks to expand on, by applying sensors (in this research as video-
based sensors, CCTVs) which could apply simple logic criterion such as green light
extension, gap out to eliminate timing gaps and max out to let the max traffic flow in each
Highway Administration Office of Operations defines a key mode that will be simulated
by the research – Fully-Actuated Control. This refers through which for a given
6
intersection, all its phases are actuated, thus the need for detection is needed (US
The actuated mode of control is required for digital detection to be integrated into
the system. This type of control is available in the Philippines with Cebu City spending
480 million pesos, using the fully adaptive countdown timers, maximizing CCTVs with
Artificial Intelligence detection for fully actuated control (Sunnexdesk, 2023). This type of
project is already available and is in production. However, Computer vision solutions are
still continuously studied which present problems regarding the quality of inferences at
night. Thus, the research presents a hybrid method of image classification and object
detection.
Studies regarding the use of Computer Vision for Traffic Light Control present
models which either used a type of image classification, object detection or even image
segmentation. A single model is deployed on the desired application system. The method
proposed is to use object detection by the YOLO (“You Only Look Once”) technique and
SORT (Simple Online and Real-time Tracking algorithm) to track different objects in the
given frames. This method then uses the count of objects to facilitate the timing of the
traffic lights. However, due to the nature of Computer Vision relying on the camera input
to provide an inference, when vehicles are close to the camera frames or cast large shadows,
and at night, the accuracy of inference suffer (Sharma et al., 2021). Using YOLO as a
single approach or using object detection on its own, in general, tends to affect the
calculation of traffic density, with which many approaches are also studied.
7
Simple computer vision techniques such as image processing have also been
manually looking for features that would define traffic density. Edge detection produces
contours, which then segments the image into different contour segments. The binary
regions of the vehicle contours were counted, which equates to manually defining a vehicle
using contour, and is then used to calculate the overall traffic density (Nodado et al., 2018).
Other techniques studied are variations of image processing which uses kernels to
do edge detection and then use a feature based matching technique to calculate traffic
density. A reference image with empty vehicles matched with a target match image with
vehicles, including percentage confidence, defines the traffic density. The higher
confidence level of the feature matching, the lesser the density of the traffic (Meng et al.,
2021).
Thus, with the direction of the research, two different model computer vision
approaches would be used to create inference for the traffic light. With image classification
and object detection techniques working simultaneously on runtime, the researchers seek
to create a reliable method for actuating traffic signals. With these, the YOLOv8n model
was chosen due to its reliability and fast inference times, effective for real-time processing.
The model is compared with other previous YOLO versions and YOLOv8 is the highest
performing model even at its smallest model size as shown in Figure 2 (Reis et al., 2023).
8
Figure 2. YOLOv8 Comparison to Previous Versions of YOLO. Adapted from
Ultralytics, 2024.
This model architecture for object detection, YOLO short for "You Only Look
Once," is an innovative approach to object detection by putting it into a grid system which
uses a single end-to-end convolutional neural network which makes it an extremely fast
and simple model, fit for real-time applications. A model that continues to scale and grow
and be continuously modified to fit the growing demand in object detection (Redmon et
al., 2016). Many implementations of YOLO perform significantly better than other state of
the art detectors, especially in the inference times with which even for its smaller versions,
it is performing with comparable mAP of normal sized model of other detectors (Long et
al., 2020).
9
Figure 3. Comparison of YOLO and other state of the art detectors. Adapted from Long
et al., 2020.
And with the fast development of versions of this new model architecture,
YOLOv8 was created and is still in active development at the time of writing. This state-
of-the-art YOLO model is a new way to follow up on previous studies done. This model
has a high rate of accuracy measured by Microsoft COCO and Roboflow 100, this also
comes with many features that will help us develop the model both in image classification
and object detection (Solawetz & Francesco, 2023). This model will be employed by the
vision.
10
Definition of Terms
● Computer Vision – the use of computer machines to interpret and recognize visual
objects.
system that can learn a specific way of thinking by past data to predict outcomes
● Deep Learning – a subset of Machine Learning that uses artificial neural networks
to create more complex predictive models that imitate the human brain learning
process.
image or video.
another task.
● One Stage Model – class of object detection architectures that is synonymous with
transfer learning for this research with it being a model being reused for another
task.
11
● Inference (Machine Learning) – the process of running data points into a machine
● Dataset – data gathered for training the model; in this research, it is referred to as
images.
applications.
road intersections.
● Traffic Density – the measurement of how much traffic is at a given location area.
● Exclusive Phase – a traffic signal phase with which at a go/green signal, a single
Theoretical Framework:
As displayed in Figure 4, there are four stages the whole optimized light control
system must complete: the Dataset preparation, the Model pipeline, the Model inference
12
Figure 4. Hybrid Image Classification and Object Detection for Traffic Light Optimization
Framework
The Dataset stage is a process where the data set is gathered and prepared. There
are two datasets prepared; one for the image classification with labels Fire, Accident,
Sparse Traffic, and Dense Traffic; and one for the object detection with labels Person, Car,
The Model (Machine Learning) Pipeline stage starts at the input of the dataset and
ends with the model exportation or packaging, wherein it would then be used for inference.
For image classification and object detection, there are 2 YOLOv8 models chosen, namely
the yolov8n-cls for classification and yolov8n for detection. These models will be analyzed
13
The Model Inference processing stage is where the computation for the Traffic
Light Control System happens. Both image classification and object detection are set for
inference and with which both are considered for the interpretation of the Traffic Light
Signal. This would then be the input for the Application Stage composed of the Traffic
14
CHAPTER 3
The research materials are composed of software components, the transfer learning
models to be used, and the electronics components with which the inferences will be run,
MATERIALS
Software Components:
● Python
● Ultralytics
● Google Colab
● YOLOv8n
Table 1 shows that YOLOv8n is the fastest of all the YOLOv8 models due to its
smaller parameter size at 3.2 million parameters. It has a fast inference speed at
0.99ms on an A100 TensorRT. Thus, this model is chosen to give the fastest
15
Table 1
YOLOv8n Performance
● YOLOv8n-cls
Table 2 displays that this model is also the fastest of all the YOLOv8 classification
models due to its smaller parameter size at 2.7 million parameters. It has a fast
16
Table 2
YOLOv8n-cls Performance
Datasets:
● Traffic-Net Dataset
17
Electronic Components:
Arduino Uno - The Arduino Uno as exhibited in Figure 5, functions as the GPIO
extension of the computing device. It controls and manages the electronic Inputs
18
BEAGLEBONE BLACK: SPECIFICATIONS
Foundation, 2024.
ESP32 cam - The ESP cam, as shown in Figure 7, serves as a CCTV proxy and the
ESP32: SPECIFICATIONS
19
Traffic Light Module (Red, Green, Yellow) - This module in Figure 8, serves as
as the mediating interface between the 5V Arduino Uno and the 3.3V Beaglebone
Black. It helps the GPIO input and output of the devices communicate with each
other.
20
METHODOLOGY
The methods used are composed of the solutions used for the specific research
objectives: the Model Pipeline, the CCTV and Proposed System Integration Prototype, and
The machine learning pipeline was defined in Figure 10, with the input
from the Image Classification dataset and the Object Detection dataset. Data
Preparation is organizing the structure of the dataset including the data split of 70%
training set, 15% test set, and 15% validation set. After splitting the data, the data
is fed to the model training with which a transfer model is also chosen for a set of
training. The transfer models used are based on the YOLOv8 with optimized
weights in its layers that will define the feature scaling of the image inputs. The
Gigabytes of RAM and a dedicated GPU for training the model. Model Analysis
and Validation is also run in the same Colab instance, with which, it would be
retrained and refined. The model is then Exported after a series of retraining and
validation. The export will be in a PyTorch model format which would be easily
converted for inference with multiple edge devices. The model is then deployed to
21
Figure 10. Image Classification and Object Detection Deep Learning Pipeline
metrics are Accuracy as displayed in Figure 11. As for the Object Detection, the
Accuracy, the mAP (mean Average Precision) will be applied, which is the area
𝑇𝑟𝑢𝑒 𝑃𝑜𝑠𝑖𝑡𝑖𝑣𝑒
𝑃𝑟𝑒𝑐𝑖𝑠𝑖𝑜𝑛 =
𝑇𝑟𝑢𝑒 𝑃𝑜𝑠𝑖𝑡𝑖𝑣𝑒 + 𝐹𝑎𝑙𝑠𝑒 𝑃𝑜𝑠𝑖𝑡𝑖𝑣𝑒
𝑇𝑟𝑢𝑒 𝑃𝑜𝑠𝑖𝑡𝑖𝑣𝑒
𝑅𝑒𝑐𝑎𝑙𝑙 =
𝑇𝑟𝑢𝑒 𝑃𝑜𝑠𝑖𝑡𝑖𝑣𝑒 + 𝐹𝑎𝑙𝑠𝑒 𝑁𝑒𝑔𝑎𝑡𝑖𝑣𝑒
22
Figure 12. Sample Precision-Recall Curve
The model architecture is defined by Figure 13. The model has 225 layers,
operations). Transfer models typically freeze backbone layers and add layers at the
head for the output, but YOLO implementation typically does not freeze layers
during the transfer learning process, rather it updates the weights of the final layers
using gradient descent, in this case the researchers utilized AdamW optimizer to
fine-tune the model. The difference between the image classification and the object
detection model is the last layer, which is the Bbox and the Cls. layer, both of which
calculate the loss. The researchers fine-tuned the whole model and froze the last
optimal state.
23
Figure 13. YOLOv8 Architecture, visualization made by GitHub user RangeKing.
effectively make a reliable detection system. In Figure 14, we can see a sample
Image Classification (on the left), with which the whole image is processed and
inputted to the Image Classification model and then outputs a result from the labels
with which the model is trained with. With this sample, there are two labels namely,
Dense Traffic and Sparse Traffic. The image is classified as a Dense Traffic Image
with a confidence level of 1.00, which means that, if the label Dense Traffic is
trained with heavy traffic images, the image is predicted to be having heavy traffic.
24
Figure 14. Sample image classification of traffic density and sample object
The sample Object Detection (on the right) in Figure 14, takes the same
image as the sample Image Classification input. The input image is then evaluated
to look for an object that is identified as a car and then draw a bounding box into it.
The Object Detection model's output is then used to count the number of car
detections and calculate their velocity or follow their path. Combining these two
C. Inference Processing
The model is deployed and is now ready for inference. As seen in Figure
15a, the program process can be divided into sections and processes. The process
starts with initiating timer and variables. Followed by the output of the model
inferences of the object detection and image classification, which are then processed
according to the need for the traffic light controller. Pedestrian Signal Process flow
25
has the Person class input and then outputs a Pedestrian Signal pulse. The Next
Signal Lane Process flow uses the classes Bicycle, Car, Motorcycle, Bus and Truck
of object detection and the Sparse Traffic and Dense Traffic of the image
classification. This sends a Next Signal Lane pulse to the controller. The Warning
Signal Process flow uses the Fire and Accident output classes of the image
26
The variables initiated initially are shown in Figure 15b. The process starts
with the lane clock timer, then initiating the needed variables and user-defined
constants. The variables are initiated to be consistently used throughout the entire
process.
Figure 15c shows how the system processes the signal for the pedestrian
actuation. The process starts with counting the pedestrian inference of the output
then if there if it is True, it will start a Pedestrian Wait Clock timer. The process
continues by counting the pedestrian again, and if the pedestrian count is greater
than the minimum count then it proceeds to add priority to the next lane. This can
also be triggered when the pedestrian has already waited at a maximum amount of
27
Figure 15c. Pedestrian Signal Process Flow.
The next process shows how the system processes the flow to change the
next signal lane or the next lane which will have a go signal. It is important to note
that the process of the lane phasing relies on the exclusive phasing. With which the
28
Figure 15d process starts with two inputs from the detection and
classification. The detection output from the model is counted along with arbitrary
weights based on their speed in going through the intersection, the space they
consume and how they interact with other motorists. The sum of the weighted count
is then added to the Total Lane Signal time. The classification output is also
processed simultaneously by checking the traffic density through the Sparse Traffic
whether to decrease or increase the time which is then added to the Total Lane
Signal Time. When the running time or Current Lane time is greater than or equal
the optimized Total Lane Signal time or the Maximum Signal time, the process at
that point outputs an actuation signal prompting the controller that it should be the
29
Figure 15d. Next Signal Lane Process Flow.
Figure 15e shows the process to output the warning signal. The input of this
operation is from the Fire and Accident classes of the classification model. The
confidence levels are received and if one of the classes is greater than the threshold
30
it will initiate a validation delay. The validation delay is to verify whether the
inference received is consistent or just a spike of the confidence value of the class.
After the validation delay the process is repeated then if its greater than threshold,
There are three main outputs of the Model Inference Processing mainly, to
initiate a warning blinking yellow lights which sends a pulse to the receiver and
31
waits for a feedback to end the warning blinking yellow lights; to initiate the next
signal lane for inference through send a pulse that immediately resets the inference
process, and to start the pedestrian signal by sending a pulse and waiting for a
feedback signaling the end of the pedestrian crossing. These outputs are from the
inference side separated from the Traffic Light Controller as discussed in further
sections.
II. CCTV System and Traffic Light System with Integrated Optimized System
The modern CCTV (Closed Circuit Television) system captures video and
functions as a video stream with multiple video frames in a single stream or a single video
on different streams, it is also called IP Cameras (Internet Protocol Camera). With this
definition, it is possible to replicate its function with an ESP32 along with its accessory
CAM OV2640. It has a WiFi module that can stream the videos captured wirelessly using
In Figure 16, the integration and the optimization of the system is seen in the block
diagram. The CCTV System Proxy and the Traffic Light System Prototype are two separate
systems integrated together using the proposed optimization system. All three systems are
electrically isolated to easily troubleshoot and scale the systems individually. These would
32
Figure 16. Block diagram of CCTV system to Traffic Light system with integration of
optimized system.
The CCTV or IP Camera will capture the live footage of the intersection. Video
footage will be taken with a drone processed at 1080p resolution. Afterwards it streams the
video directly on the computer through an IP Streaming Protocol. The programmed model
Arduino Uno. The Arduino Uno’s function is not to run the program itself but act as an
extension of the computer utilizing its IO ports as a signal actuator for the various signals
needed by the Traffic Light System prototype. There are three actuation signals received
as HIGH by the Traffic Light System: Pedestrian Signal, Next Signal Lane Lights, and
The Traffic Light System prototype consists of the Controller and the Lights. It can
(Manual Mode) that will receive signals from the Arduino Uno through the GPIO pins. The
signal exchanged between the GPIO pins of Arduino, and the Traffic Light Controller are
33
0V - 5V. The signal received by the controller replicates the ability of the Traffic Light
System to be actuated or switched by a separate signal. The pulses sent by the Optimization
System are 5V pulses which are interpreted at the rising edge by the Traffic Light System.
The electrically isolated traffic lights will be connected to multiple relays controlled by the
controller.
the industry specifications of modern traffic light systems sourced locally. In Figure 17a,
the Traffic Light System process flow is described. The traffic light includes arbitrary
variables that can be changed during runtime and to fit the observable timings from related
local intersections. The system receives actuation as 3.3V logic high to fulfill conditions.
34
Figure 17b shows how the automatic cycle works for the traffic light system
controller. The process loops the Green or “go” signal, the yellow or the “ready to stop”
signal and the “stop” signal. The values and timing are inherited values from the timing
signal of local intersection traffic lights. The signal is looped by iterating through a n-value
which is later returned to the Check Actuation Mode condition as seen on Figure 17a. The
Pedestrian signal is also part of the loop and the cycle of the whole traffic light.
Figure 17c exhibits how the automatic cycle works for the traffic light system
controller. The process loops depending on the input actuation of the following: Pedestrian,
Next Lane Signal and Warning. These are synonymous with the outputs of the model
inference. Each output corresponds to a specific sequence of timing and traffic lights. After
a single process it also iterates the n-value to go over all the phases of the intersection.
35
Figure 17c. Manual Cycle of Traffic Light Process.
The traffic light system flow will be implemented in a small demonstrable physical
model. Figure 18 displays the dimensions of the miniature traffic light system model. It
will be a four-way intersection with a traffic light led module on each lane. An extra traffic
light at the center of the intersection demonstrates the pedestrian crossing at all lanes.
36
Figure 18. Miniature Traffic Light system with proposed dimensions.
The miniature model traffic light system will be constructed around the Beaglebone
Black (BBB) microcontroller. Figure 19 shows the schematics designed and considered.
The traffic light system model from the BBB will interface with the Arduino Uno through
a Logic Level Converter that will convert 5V to 3.3V so that both devices can effectively
37
Figure 19. Traffic Light Controller and Optimized Actuator schematic.
To assess the optimized system, the mean extra green time, as seen on Figure 20,
must be compared to the actual and observed values at the local intersections. There will
be some locations along Tagaytay – Sta Rosa Rd. such as the Paseo–LTI intersection and
Greenfield Auto Parkway. Researchers observed each lane’s total red time, the total time
that the cars are stopped with the red signal; the total green time, the effective green signal
that the traffic is moving; the queue finish, the time it takes from the last vehicle that
stopped at the red signal light to cross the intersection; the extra green time, the time after
the queue finished while at green signal light; and yellow, the total time of the yellow signal
to flash. This is tested using the captured footage to estimate the extra green time.
38
𝑒𝑥𝑡𝑟𝑎 𝑔𝑟𝑒𝑒𝑛 𝑡𝑖𝑚𝑒
𝑚𝑒𝑎𝑛 %𝐸𝑥𝑡𝑟𝑎 𝐺𝑟𝑒𝑒𝑛 𝑇𝑖𝑚𝑒 = 𝛴 × 100%
𝑡𝑜𝑡𝑎𝑙 𝑔𝑟𝑒𝑒𝑛 𝑡𝑖𝑚𝑒
to provide visual ideas of image noises to solve. The ideal condition is during daylight with
ample lighting and minimal noise on the image, this will be the benchmark of the other
environmental conditions that have significant effect on the camera image quality. Images
will be collected and gathered through open-source datasets COCO and Traffic-Net that
Sample conditions are tested and compared to its actual data. The same procedure
will be done to each variable, which is to verify the model with curated validation data.
Due to the research being limited to CCTV footage at available Traffic Light intersections,
39
data gathering for multiple conditions are acquired through aerial footages, as seen in
Figure 18, where a sample aerial shot is captured at a local highway. These footages are
added to the dataset and will be augmented to simulate different environmental conditions.
It will also be labeled and annotated using a bounding box annotation and exporting it to a
YOLO format. Different highways will be captured at different time intervals and
environmental conditions which will be used for testing the model functioning real-time
following: Daylight – Brightness between +20% and +0%, the footage is the one captured
Fog – Blur up to 4.5px, Exposure between -10% and +10%, the footage used is at daytime;
and Rain – Blur up to 3 px, Noise up to 8% of pixels, the footage used is both at daytime.
Notice that Fog and Rain conditions use the daytime footage, since at night, further
augmentation will lead to undesirable results, or rendering the footage unusable. This
augmentation will be done to Object Detection and Image Classification but the validation
dataset for image classification will be purely augmented with the difference that the
“Night” variable will have an augmentation step of Brightness between -40% and 0% and
40
DESIGN CONSTRAINTS
1. Regulatory Constraint
Due to the restrictions imposed by the Republic Act 10173 – Data Privacy
Act of 2012 and security measures enforced by the Local Government Unit, access
As a workaround, the researchers opted to develop and test the system on a small
miniature scale, which is representative of the data available from the local
government.
2. Safety Constraint
associated with its current stage of development. Since the system is still in its
intersections poses potential risks. Therefore, to ensure the safety of both the
researchers and the public, testing and experimentation are confined to controlled
environments until the system is adequately refined and proven to meet safety
standards.
41
CHAPTER 4
This study determined the performance of the model and the prototype
The model results consist of object detection and image classification metrics
a. Object Detection
The first metric for object detection is the Precision-Recall (PR) curve. As shown
in Figure 22, the graph follows a curve at the upper right of the plot. This means it is doing
well for an object detection model with a limited dataset and a separate set of validation
data. The area under the PR curve of all classes is called the mean average precision (mAP).
There are varied factors that affect the mAP such as the quality of the data that it is validated
on and the addition of different augmentation techniques in the validation data to produce
validation on COCO 2017 of the YOLOv8n is at 37.3 (Jocher et al., 2023). And as seen on
Figure 23, the trained model produced a 38.6 mAP50-95 score on a custom validation
dataset. The model also started converging at around 20 epochs and continued to decrease
losses at the end of the 100 epoch, which is a good sign of a model preventing overfitting.
42
Figure 22. Object Detection Precision-Recall Curve
43
Figure 24 offers an insight of the classes that contributed much to the model
performance. The best performing class is that car class. The class is also the most
represented having around 6000 instances with the next labels represented at around 3000
instances. This is important because the car class contributes an average of 90% of all total
time inferences. The model is struggling to validate persons class since the distance of the
Figure 25 displays the sample inference output on some actual images. It can be
observed that there are some errors in the prediction such as predicting in the background,
not properly classifying the class of a bounding box, or not predicting at all. These errors
44
are expected and will render unpredictable at different actual scenarios. Thus, this will be
Figure 25. Sample Object Detection Prediction. (left prediction, right actual).
b. Image Classification
The main metric for the classification is accuracy. Figure 26 exhibits the top 1
accuracy or the first class to have the highest confidence level on inference to be 94.3%.
The baseline accuracy for the model YOLOv8n-cls is at 69.0%, thus contributing most of
the reliability to the overall inference process that the object detection method cannot
45
Figure 26. Image Classification Validation Results.
The model is doing well in its accuracy for predicting the state of a given traffic
intersection image. Looking at the classes’ individual performance as shown in Figure 27,
the model performed best on detecting accidents and fire with confidences of 0.97 and
0.99, respectively. The sparse traffic and dense traffic are used together to perform
continuous inferences or evaluation on the frames of the real time processing of traffic
timing.
46
The model relies on available datasets for use to train the image classification
dataset, thus, with the given dataset, the classification of manually curating the dataset
Figure 28 shows the sample inference output of the classification model. The
difference between the prediction and the actual might be reasonable since the model may
have given weight on the sign as to predict an accident rather than a mere sparse_traffic.
This is also the same as the dense_traffic actual data, which the model has given a
reasonable prediction of sparse_traffic, since it does not clearly show the density of cars in
the image.
Figure 28. Sample Image Classification Prediction (left prediction, right actual).
47
II. Optimized Traffic Light Timing
The optimized system is integrated into the traffic light system and the proxy CCTV
system by local file, IP stream or ESP32 with several types of CAM OV2640 (when
conditions are right for outside demonstration). The video image sizes are at a Full HD
The script runs are tested on a MacBook Pro M1 device to handle inferences with the
trained YOLOv8n and YOLOv8n-cls. These are small models with a weight (pytorch) file
of around 6MB. Thus, with the strong processing unit and a smaller model, the inferences
run at a speed of 1.6-5.1 ms per frame. This would easily be translated to edge devices,
since the YOLOv8 model can be exported directly onto other models such as Tensorflow
The inferences are also utilized by the miniature system and performs as expected
by changing the required lanes along with the inferences that happen on the inference
machine. The integration with the miniature system can be easily scaled up since the
inference is at a separate device only actuating the logic required by the controller. The
actuation signal can also be transferred wirelessly using IP protocol and a script that can
Table 3 shows observed traffic data from local intersections that at non-peak hours,
the queue finishes early and demonstrates a 38.28% mean %extra green or go time after
the queue finishes. And the LTI-Paseo traffic intersection where the optimized system will
be tested. This is compared to the optimized system which decreased the mean %extra
48
Table 3
1 62 60 32.0 28.0 3
1 82 35 20.3 14.7 3
2 82 35 18.7 16.3 3
LTI-Paseo
Actual 3 85 35 30.3 4.7 3
Note. Averaged timing data at local intersections at Santa Rosa, Laguna during non-peak
hours.
49
The results do not count total red as the time depends on the density of traffic. The
total green time accounts for the traffic density and the queue it selects for the region where
it detects traffic. There are pedestrian crossing points present at LTI-Paseo intersection, but
they are seldom used by pedestrians. The system can detect these pedestrians at corners
where they can start crossing. However, the pedestrian feature of the model is an extra
feature wherein it assumes that when many pedestrians need to cross, all the lanes need to
stop.
Another assumption that has been made at optimizing the lanes is that these lanes
should have an exclusive phase. The phases in which inferences are made have a phase
rotation that allows concurrent lanes to be in a single phase, this means that the cycle of
both systems differ. Though the systems differ, the assumption removes complexity from
the timing situations and allows for better optimization of the green light time (Buckholz,
2024).
The conditions are validated using augmented images of the validation dataset, this
does not reflect actual condition performance. For example, Rain condition takes noise
augmentations and some exposure augmentations. Table 4 displays that the validation
performance of the image classification using classify, reached accuracy of equal or greater
than 98%, giving weight to the importance of using image classification alongside an object
detection model. The object detection validation scores fall short at nighttime since the
camera cannot capture useful information in the dark without processing or equalizing the
50
Table 4
condition. Its inference outputs true results for detection and classification, with some
boxes. These night conditions could be better utilized by doing equalization and image
51
Figure 29. Sample validation of different environmental conditions.
52
CHAPTER 5
Conclusion
This study aimed to optimize traffic light control through the integration of
computer vision techniques and a hybrid approach to traffic signal timing. With a goal to
contribute to the current developments to address traffic and land transportation issues in
the Philippines, the researchers designed the computer vision hybrid system to optimize
traffic light control composed of image classification and object detection techniques. This
Thus, through extensive development and careful evaluation, this research yields
mAP of 37.3%. This indicates the robustness of the model in accurately detecting
achieved an impressive top-1 accuracy of 98% on the validation dataset. This high
53
accuracy rate enhances the reliability of the overall inference process, particularly
in identifying critical traffic conditions such as accidents and fires. The model's
conditions.
The optimized traffic light system significantly reduced the mean %extra
intersection. This substantial reduction in wasted green light time demonstrates the
Additionally, the integration of the optimized system actuation with the miniature
traffic light prototype displayed its scalability and adaptability for real-world
deployment.
particularly during nighttime and adverse weather conditions. While the system
54
computer vision techniques, such as object detection and image classification by using
forward, continued research and development efforts are essential to refine and optimize
these systems for widespread adoption, leading to safer and more efficient urban
transportation networks.
Recommendation
Based on the findings of this study, the following recommendations are proposed:
fog, and rain. Exploring advanced image processing techniques and data
Improving the camera technologies would also help the overall computer vision
system.
The system is also reliant on the model used and the dataset it was trained
on, thus, the researchers advocate for aligning the future direction of this research
address the dynamic nature of traffic data over time. This entails the seamless
55
2. Field Testing
traffic intersections would provide valuable insights into its effectiveness and
to implement pilot projects could validate the system's performance in live traffic
scenarios.
optimized system across various intersections and urban environments. The studied
design.
improvement, the potential for real-world deployment and impact is enhanced. This
ensures that traffic management systems remain adaptable and responsive to the changing
dynamics of urban traffic, contributing to safer and more efficient transportation networks
in the cities.
56
REFERENCES
Agarwal, S., & Kumar, P. (2016). SMART TRAFFIC CONTROL SYSTEM BASED ON
http://www.ir.juit.ac.in:8080/jspui/bitstream/123456789/7563/1/Smart%20Traffic
%20Control%20System%20Based%20on%20Vehicle%20Density.pdf
https://docs.arduino.cc/hardware/uno-rev3/
Docs.beagleboard.org.
https://docs.beagleboard.org/latest/boards/beaglebone/black/
https://www.cedengineering.com/userfiles/Introduction%20to%20Traffic%20Sig
nal%20Phasing-R1.pdf
CNN Philippines Staff (2022, August 1). CNN Philippines. Retrieved December 5, 2023,
from http://www.cnnphilippines.com/news/2022/8/1/MMDA-countdown-
stoplights-adaptive-traffic-signals.html
Eom, M., & Kim, B.-I. (2020). The traffic signal control problem for intersections: a
https://doi.org/10.1186/s12544-020-00440-8
https://newsinfo.inquirer.net/561705/mmda-upgrades-traffic-system
57
JICA (2022, February 10). Ex-Ante Evaluation Southeast Asia Division 5 Southeast Asia
P275_1_s.pdf
Jocher, G., Chaurasia, A., & Qiu, J. (2023). Ultralytics YOLO (Version 8.0.0) [Computer
software]. https://github.com/ultralytics/ultralytics
Long, X., Deng, K., Wang, G., Zhang, Y., Dang, Q., Gao, Y., Shen, H., Ren, J., Han, S.,
https://doi.org/10.48550/arxiv.2007.12099
Meng, B. C. C., Damanhuri, N. S., & Othman, N. A. (2021). Smart traffic light control
system using image processing. IOP Conference Series: Materials Science and
Nodado, J. T. G., Morales, H. C. P., Abugan, M. A. P., Olisea, J. L., Aralar, A. C., &
https://doi.org/10.1109/TENCON.2018.8650084
https://docs.platformio.org/en/latest/boards/espressif32/esp32cam.html
Redmon, J., Divvala, S., Girshick, R., & Farhadi, A. (2016, May 9). You only look once:
Reis, D., Kupec, J., Hong, J., & Daoudi, A. (2023). Real-Time Flying Object Detection
58
Sharma, M., Bansal, A., Kashyap, V., Goyal, P., & Sheikh, T. H. (2021). Intelligent
012122. https://doi.org/10.1088/1757-899x/1022/1/012122
Solawetz, J., & Francesco. (2023, January 11). What is YOLOv8? The Ultimate Guide.
Sunnexdesk (2023, January 23). Cebu’s traffic light system “most advanced” in world.
traffic-light-system-most-advanced-in-world
Rouphail, N., Tark, A., & Li, J. (1997). TRAFFIC FLOW AT SIGNALIZED
https://www.fhwa.dot.gov/publications/research/operations/tft/chap9.pdf
https://ops.fhwa.dot.gov/publications/fhwahop08024/chapter5.htm
Zaldarriaga, J. (2023, January 31). MMDA’s Artes on the right track in pushing road
mmdas-artes-on-the-right-track-in-pushing-road-safety
59
APPENDICES
60
Appendix B: Local Government Cooperation Summary
and Santa Rosa City – City Traffic and Management Enforcement Unit
(Left to Right)
The researchers visited the Local Government Unit Offices of Santa Rosa City
CTMEU (City Traffic and Management Enforcement Unit) and Santa Rosa City
Command Center to reach out for advice and additional information regarding the Traffic
● The Traffic Light System has an Automatic and Manual Actuation Mode that can
be controlled both by the Command Center and on-site at the Traffic Light
Systems.
● The Automatic Actuation Mode is a fixed timer that can be set to separate times at
● The Manual Actuation mode can be controlled by the CTMEU personnel when
there is a need for manual control of the traffic flow at heavy-traffic time slots.
61
● The Traffic Light System is powered by 220V, and its internal microcontrollers
are at 9-24V.
These information are essential for understanding the systems currently used in
the Philippines. These are also the basis of arbitrary and base constants used by the
The researchers also requested some of the video footage for inference. However,
due to the Republic Act 10173 – Data Privacy Act of 2012 and security measures by the
Local Government Unit, limited information is given, and CCTV footage access is
restricted. The system's implementation requires some cooperation from the local
government, which the researchers are denied. Thus, the researchers decided to
implement the traffic light optimization system on a small miniature scale that is
There are revisions and updates after the decision to scale down the project. It is
62
Appendix C: Change Matrix
Change Page
Code. Rationale Original Revised No.
2. Model performance is
Unable to access dependent on the available 2. Model performance is
local intersection datasets such as COCO, dependent on the
CCTV footage datasets with open-source available datasets such
from Local attribution and local as COCO and datasets
Government intersection CCTV footages with open-source
B1 Units. from Local Government Unit. attribution. 7
Scope and Limitation
Implementation is
not possible for 3. Implementation will be
existing traffic done at a local 4-way
light systems. A intersection at the CALAX -
makeshift system Sta. Rosa Tagaytay Rd. T
is possible but intersection and Nuvali
may prove unsafe Greenfield Pkwy. - Sta. Rosa
for Tagaytay Rd. 4-way Redacted
B2 implementation. intersection. 7
63
Researchers
agreed to use a
proxy stream to IP
or an ESP32
CAM as a CCTV,
IP Camera
alternative or
local accessible 3. The CCTV system
CCTV footage of will be proxied through
the highway. video streams instead of
Researchers a real-time stream due to
assume that any security and safety
highway with factors. CCTV video
traffic flow is will be sourced at a local
representative of Scope and Limitation 4-way intersection or T
an inference at a intersection using on-
B3 green light lane. Append Revision site footage. 7
64
Appendix D: Request Letter for CCTV and Traffic Light Access
65
Appendix E: Traffic Light Lanes Raw Data
1 137 58 23 35 3
137 58 33 25 3
137 58 30 28 3
2 175 20 18 2 3
175 20 17 3 3
Greenfield Autopark 175 20 16 4 3
3 120 75 50 25 3
120 75 50 25 3
120 75 48 27 3
4 170 25 12 13 3
170 25 23 2 3
170 25 20 5 3
1 62 60 27 33 3
62 60 37 23 3
62 60 32 28 3
2 107 15 8 7 3
107 15 11 4 3
Laguna Bel-Air
107 15 12 3 3
3 62 60 30 30 3
62 60 42 18 3
62 60 28 32 3
66
4 107 15 10 5 3
107 15 7 8 3
107 15 9 6 3
1 82 35 20 15 3
82 35 23 12 3
82 35 18 17 3
2 82 35 17 18 3
82 35 19 16 3
LTI-Paseo
Actual 82 35 20 15 3
3 85 35 29 6 3
85 35 32 3 3
85 35 30 5 3
4 100 14 11 3 3
100 14 7 7 3
100 14 9 5 3
1 N/A 51 44 7 3
LTI-Paseo N/A 51 41 10 3
Optimized System at
gathered footage 2 N/A 32 29 3 3
N/A 32 30 2 3
3 N/A 45 40 5 3
N/A 45 42 3 3
4 N/A 20 19 1 3
N/A 20 19 1 3
67
Appendix F: Source Code
import argparse
from collections import defaultdict
from pathlib import Path
import time
import pyfirmata
import asyncio
import cv2
import numpy as np
from shapely.geometry import Polygon
from shapely.geometry.point import Point
track_history = defaultdict(list)
start_region = None
counting_regions = [
{
"name": "Pedestrian Region",
"polygon": Polygon([(900, 700), (1200, 700), (1200, 500), (900, 500)]), # Polygon points
"counts": 0,
"dragging": False,
"region_color": (255, 155, 100), # BGR Value
"text_color": (255, 255, 255), # Region Text Color
},
{
"name": "Multiplier Region",
"polygon": Polygon([(400, 650), (700, 650), (650, 50), (500, 50)]), # Polygon points
"counts": 0,
"dragging": False,
"region_color": (100, 200, 255), # BGR Value
"text_color": (0, 0, 0), # Region Text Color
},
]
board.digital[12].write(1)
await asyncio.sleep(1)
board.digital[12].write(0)
next_source = True
68
board.digital[8].write(1)
await asyncio.sleep(1)
board.digital[8].write(0)
await asyncio.sleep(10)
board.digital[8].write(1)
await asyncio.sleep(0.5)
board.digital[8].write(0)
board.digital[12].write(1)
await asyncio.sleep(1)
board.digital[12].write(0)
#next_source = True
board.digital[7].write(1)
await asyncio.sleep(1)
board.digital[7].write(0)
await asyncio.sleep(10)
board.digital[7].write(1)
await asyncio.sleep(1)
board.digital[7].write(0)
#next_source = True
def reset_variables():
"""Reset or reinitialize variables."""
global max_lane_signal_time, total_lane_signal_time, start_lane_time
global max_pedestrian_wait_time, start_pedestrian_wait_time, pedestrian_count
global pedestrian_detected, detect_added, classify_added, next_source
max_lane_signal_time = 120
total_lane_signal_time = 0
start_lane_time = time.time()
max_pedestrian_wait_time = 10
start_pedestrian_wait_time = 0
pedestrian_count = 0
pedestrian_detected = False
detect_added = 0
classify_added = 43
next_source = False
69
for r in results_cls:
# Iterate over each class in the classification results
for label, prob in zip(top5_labels, top5_conf_np):
# Apply conditions based on class probabilities
if label == "sparse_traffic" and prob > 0.80:
classify_added *= 0.5
elif label == "dense_traffic" and prob > 0.30:
classify_added *= 1.2
elif label == "fire" and prob > 0.60:
#cv2.putText(frame,"WARNING", (600, 300), cv2.FONT_HERSHEY_SIMPLEX, 3, (0, 140,
255), 2)
#asyncio.run(warning_go())
continue
elif label == "accident" and prob > 0.60:
#cv2.putText(frame,"WARNING", (600, 300), cv2.FONT_HERSHEY_SIMPLEX, 3, (0, 140,
255), 2)
#asyncio.run(warning_go())
continue
def pedestrian_signal(pedestrian_count):
global start_pedestrian_wait_time, pedestrian_detected, next_source
if not pedestrian_detected:
if pedestrian_count >= 3:
start_pedestrian_wait_time = time.time() # Start the pedestrian wait time counter
print("Pedestrian wait time started")
pedestrian_detected = True
else:
print("Pedestrian signal: Stop")
else:
pedestrian_elapsed_time = time.time() - start_pedestrian_wait_time
print(f"elapsed_pedestrian_time: {pedestrian_elapsed_time}")
70
next_source = True
time.sleep(3)
asyncio.run(next_lane_go())
global start_region
def run(
source=None,
device="cpu",
hide_img=False,
board_port='/dev/tty.usbmodem1401',
line_thickness=2,
track_thickness=2,
region_thickness=4,
):
board = pyfirmata.Arduino(board_port)
print("Communication Successfully started")
vid_frame_count = 0
71
raise FileNotFoundError(f"Source path '{source}' does not exist.")
# Setup Model
model = YOLO("runs/detect/train3/weights/best.pt")
model.to("cuda") if device == "0" else model.to(device)
model_cls = YOLO("runs/classify/train2/weights/best.pt")
model_cls.to("cuda") if device == "0" else model_cls.to(device)
# Video setup
videocapture = cv2.VideoCapture(source)
# Classification results
for r in results_cls:
# Convert the tensor to a numpy array
top5_conf_np = r.probs.top5conf
72
classes_with_multiplier = {'bicycle': 0, 'bus': 0, 'car': 0, 'motorcycle': 0, 'truck': 0}
detect_added = sum(classes_with_multiplier.values())
region_color = region["region_color"]
region_text_color = region["text_color"]
73
polygon_coords = np.array(region["polygon"].exterior.coords, dtype=np.int32)
centroid_x, centroid_y = int(region["polygon"].centroid.x), int(region["polygon"].centroid.y)
text_size, _ = cv2.getTextSize(
region_label, cv2.FONT_HERSHEY_SIMPLEX, fontScale=0.7, thickness=line_thickness
)
text_x = centroid_x - text_size[0] // 2
text_y = centroid_y + text_size[1] // 2
cv2.rectangle(
frame,
(text_x - 5, text_y - text_size[1] - 5),
(text_x + text_size[0] + 5, text_y + 5),
region_color,
-1,
)
cv2.putText(
frame, region_label, (text_x, text_y), cv2.FONT_HERSHEY_SIMPLEX, 0.7,
region_text_color, line_thickness
)
cv2.polylines(frame, [polygon_coords], isClosed=True, color=region_color,
thickness=region_thickness)
pedestrian_signal(pedestrian_count)
if not hide_img:
if vid_frame_count == 1:
cv2.namedWindow("Optimized Traffic Light Inference Mode")
cv2.setMouseCallback("Optimized Traffic Light Inference Mode", mouse_callback)
cv2.imshow("Optimized Traffic Light Inference Mode", frame)
if next_source:
break
74
del vid_frame_count
videocapture.release()
cv2.destroyAllWindows()
def parse_opt():
"""Parse command line arguments."""
parser = argparse.ArgumentParser()
parser.add_argument("--device", default="cpu", help="cuda device, cpu or mps")
parser.add_argument("--hide-img", action="store_true", help="hide results")
parser.add_argument("--board-port", required=True, help="ls /dev/tty.*")
return parser.parse_args()
def main(opt):
"""Main function."""
# List of source paths
source_list = [
"traffic-view/Paseo-1.mp4",
"traffic-view/Paseo-2.mp4",
"traffic-view/Paseo-3.mp4",
"traffic-view/Paseo-4.mp4",
"traffic-view/Paseo-5.mp4",
"traffic-view/Paseo-6.mp4",
"traffic-view/Paseo-7.mp4",
"traffic-view/Paseo-8.mp4"
]
while True:
for source_path in source_list:
reset_variables()
opt.source = source_path
run(**vars(opt))
if __name__ == "__main__":
opt = parse_opt()
main(opt)
75
Appendix G: Similarity Index
Similarity Index: 3%
Artificial Intelligence: --
Date of Test Conducted: Tue, 14 May 2024 15:28:08 +0800 PM PST
3
Copyright 2019. All Rights Reserved.
76
Appendix H: Certificate of Technical Editing
This is to certify that I have edited the Final Draft of the thesis manuscript entitled:
Prepared by
underwent technical editing and is complete in terms of inventive steps, grammar, APA
format as prescribed by this office.
Mayoliewin N. Taclan
Editor
77
CURRICULUM VITAE
78
79
80