Real-Time Traffic Density and Anomaly Monitoring Using YOLOv8, OpenCV and Pattern Recognition for Smart City Applications in Demak
DOI:
https://doi.org/10.52436/1.jutif.2025.6.4.4867Keywords:
Anomaly Detection, Pattern Recognition, Real-Time Monitoring, Vehicle Density Detection, Yolov8Abstract
Urban traffic congestion is a persistent issue in medium-sized cities like Demak, leading to delays and potential accidents. This study presents the development of a real-time vehicle density and anomaly detection system using YOLOv8, combined with OpenCV for video analysis, to monitor traffic flow at strategic entry points of Demak City. The system classifies vehicles into four categories (cars, motorcycles, trucks, buses) and determines their direction by detecting crossing lines. A key feature is the recognition of vehicle patterns, particularly the detection of stopped vehicles, flagging anomalies after 30 seconds of stoppage, with tolerance for temporary detection losses. Traffic data is stored in CSV format, enabling periodic analysis and visualization via an interactive graphical user interface (GUI). Evaluation results show the YOLOv8n model achieves 92.5% precision, 88.3% recall, and 89.7% mean average precision (mAP@0.5), demonstrating improved accuracy and speed over previous YOLO versions. Additionally, the vehicle counting accuracy reaches 94.2% when compared with manual annotations. The proposed system provides a reliable solution for real-time traffic monitoring and early anomaly detection, supporting intelligent transportation systems (ITS) and enabling data-driven traffic management decisions. This research contributes to the advancement of real-time video analytics and pattern recognition for urban traffic control and serves as a scientific reference for the development of smart city infrastructures. Furthermore, this study strengthens the application of pattern recognition in intelligent anomaly detection, providing new insights for researchers in the fields of computer science and informatics.
Downloads
References
R. Zhao, S. H. Tang, E. E. Bin Supeni, S. A. Rahim, and L. Fan, “Z-YOLOv8s-based approach for road object recognition in complex traffic scenarios,” Alexandria Engineering Journal, vol. 106, pp. 298–311, Nov. 2024, doi: 10.1016/j.aej.2024.07.011.
D. Nimma et al., “Object detection in real-time video surveillance using attention based transformer-YOLOv8 model,” Alexandria Engineering Journal, vol. 118, pp. 482–495, Apr. 2025, doi: 10.1016/j.aej.2025.01.032.
Z. Hu, W. H. K. Lam, S. C. Wong, A. H. F. Chow, and W. Ma, “Turning traffic surveillance cameras into intelligent sensors for traffic density estimation,” Complex and Intelligent Systems, vol. 9, no. 6, pp. 7171–7195, Dec. 2023, doi: 10.1007/s40747-023-01117-0.
R. Liu and S. Y. Shin, “A Review of Traffic Flow Prediction Methods in Intelligent Transportation System Construction,” Apr. 01, 2025, Multidisciplinary Digital Publishing Institute (MDPI). doi: 10.3390/app15073866.
J.-G. Jang and Y.-W. Kwon, “Trajectory Similarity-Based Traffic Flow Analysis Using YOLO+ByteTrack,” Journal of Multimedia Information System, vol. 12, no. 1, pp. 27–40, Mar. 2025, doi: 10.33851/JMIS.2025.12.1.27.
Y. Zhang, Z. Guo, J. Wu, Y. Tian, H. Tang, and X. Guo, “Real-Time Vehicle Detection Based on Improved YOLO v5,” Sustainability (Switzerland), vol. 14, no. 19, Oct. 2022, doi: 10.3390/su141912274.
N. Al Mudawi et al., “Vehicle Detection and Classification via YOLOv8 and Deep Belief Network over Aerial Image Sequences,” Sustainability (Switzerland), vol. 15, no. 19, Oct. 2023, doi: 10.3390/su151914597.
M. Bakirci, “Real-Time Vehicle Detection Using YOLOv8-Nano for Intelligent Transportation Systems,” Traitement du Signal, vol. 41, no. 04, pp. 1727–1740, Aug. 2024, doi: 10.18280/ts.410407.
E. Benitha Sowmiya, Y. Sai, P. Chandra, S. H. Kishore, G. N. Goud, and N. S. Prakash, “International Journal of Innovative Research in Science Engineering and Technology (IJIRSET) Smart Traffic Analysis, Monitoring, and Density Estimation System Using YOLOv8”, doi: 10.15680/IJIRSET.2025.1404481.
J. Anzola, I. Aizpuru, A. Arruti, J. S. Artal-Sevil, and C. Bernal, “Demystifying Non-Isolated DC–DC Topologies on Partial Power Processing Architectures,” Electronics (Switzerland), vol. 11, no. 3, Feb. 2022, doi: 10.3390/electronics11030480.
H. A. Saputri, M. Avrillio, L. Christofer, V. Simanjaya, and I. N. Alam, “Implementation of YOLO v7 algorithm in estimating traffic flow in Malang,” in Procedia Computer Science, Elsevier B.V., 2024, pp. 117–126. doi: 10.1016/j.procs.2024.10.235.
N. Manoj, Mohana, A. S. Manu, N. Y. Mallikarjun, P. Ramakanth Kumar, and K. Sreelakshmi, “Vehicle Detection, Counting and Classification Using YOLOv8 Deep Learning Model and OpenCV for Urban Traffic Management System,” in Proceedings of the 9th International Conference on Communication and Electronics Systems, ICCES 2024, Institute of Electrical and Electronics Engineers Inc., 2024, pp. 2085–2090. doi: 10.1109/ICCES63552.2024.10860266.
C. Li, Y. Zhu, and M. Zheng, “A multi-objective dynamic detection model in autonomous driving based on an improved YOLOv8,” Alexandria Engineering Journal, vol. 122, pp. 453–464, May 2025, doi: 10.1016/j.aej.2025.03.020.
R. Juliansyah et al., “Development of a Real-Time Traffic Density Detection Website Using YOLOv8-Based Digital Image Processing with OpenCV,” Journal of Information Systems and Informatics, vol. 6, no. 4, pp. 2649–2678, Dec. 2024, doi: 10.51519/journalisi.v6i4.912.
M. Bakirci, “Utilizing YOLOv8 for enhanced traffic monitoring in intelligent transportation systems (ITS) applications,” Digit Signal Process, vol. 152, p. 104594, 2024, doi: https://doi.org/10.1016/j.dsp.2024.104594.
J. A. B. Delmo, “Deep Learning-Based Vehicle Speed Estimation in Bidirectional Traffic Lanes,” in Procedia Computer Science, Elsevier B.V., 2025, pp. 222–230. doi: 10.1016/j.procs.2024.12.024.
Y. Wang, S. Ke, C. An, Z. Lu, and J. Xia, “A Hybrid Framework Combining LSTM NN and BNN for Short-term Traffic Flow Prediction and Uncertainty Quantification,” KSCE Journal of Civil Engineering, vol. 28, no. 1, pp. 363–374, Jan. 2024, doi: 10.1007/s12205-023-2457-y.
Z. Luo et al., “Enhanced YOLOv5s + DeepSORT method for highway vehicle speed detection and multi-sensor verification,” Front Phys, vol. 12, 2024, doi: 10.3389/fphy.2024.1371320.
H. Dou, S. Chen, F. Xu, Y. Liu, and H. Zhao, “Analysis of vehicle and pedestrian detection effects of improved YOLOv8 model in drone-assisted urban traffic monitoring system,” PLoS One, vol. 20, no. 3 March, Mar. 2025, doi: 10.1371/journal.pone.0314817.
X. Lin, H. Sun, and Z. Chen, “Traffic Flow Detection Based on Improved YOLOv5 and DeepSORT,” in 2024 IEEE 4th International Conference on Information Technology, Big Data and Artificial Intelligence (ICIBA), 2024, pp. 361–367. doi: 10.1109/ICIBA62489.2024.10868180.
F. N. Kılıçkaya, M. Taşyürek, and C. Öztürk, “Performance evaluation of YOLOv5 and YOLOv8 models in car detection,” Imaging and Radiation Research, vol. 6, no. 2, p. 5757, Jul. 2024, doi: 10.24294/irr.v6i2.5757.
H. Jeon, H. Kim, D. Kim, and J. Kim, “PASS-CCTV: Proactive Anomaly surveillance system for CCTV footage analysis in adverse environmental conditions,” Nov. 15, 2024, Elsevier Ltd. doi: 10.1016/j.eswa.2024.124391.
C. Cui, L. Liu, and R. Qiao, “A cutting-edge video anomaly detection method using image quality assessment and attention mechanism-based deep learning,” Alexandria Engineering Journal, vol. 108, pp. 476–485, Dec. 2024, doi: 10.1016/j.aej.2024.07.103.
M. A. Onsu, M. Simsek, M. Fobert, and B. Kantarci, “Intelligent multi-sensor fusion and anomaly detection in vehicles via deep learning,” Internet of Things (The Netherlands), vol. 31, May 2025, doi: 10.1016/j.iot.2025.101561.
R. Leyva, V. Sanchez, C. T. Li, and C. Maple, “Specific event detection for video surveillance using variational Bayesian inference,” Neurocomputing, vol. 603, Oct. 2024, doi: 10.1016/j.neucom.2024.128291.
D. Junio Marcelleno and M. Pajar Kharisma Putra, “PERFORMANCE EVALUATION OF YOLOV8 IN REAL-TIME VEHICLE DETECTION IN VARIOUS ENVIRONMENTAL CONDITIONS,” Jurnal Teknik Informatika (JUTIF), vol. 6, no. 1, pp. 269–279, 2025, doi: 10.52436/1.jutif.2025.6.1.3916.
M. Rezaei, M. Azarmi, and F. M. P. Mir, “3D-Net: Monocular 3D object recognition for traffic monitoring,” Expert Syst Appl, vol. 227, Oct. 2023, doi: 10.1016/j.eswa.2023.120253.
T. Maurya, S. Kumar, M. Rai, A. K. Saxena, N. Goel, and G. Gupta, “Real Time Vehicle Classification Using Deep Learning—Smart Traffic Management,” Engineering Reports, vol. 7, no. 3, Mar. 2025, doi: 10.1002/eng2.70082.
C. J, G. S. Priya, C. K. Samuel, S. M, S. J, and S. A. Jebaraj, “Traffic Flow Forecasting Using Machine Learning Techniques,” Webology, vol. 18, no. 04, pp. 1512–1526, Sep. 2021, doi: 10.14704/web/v18si04/web18295.
A. Hussein, M. W. Raed, A. Al-Shaikhi, M. Mohandes, and B. Liu, “Crowd anomaly estimation and detection: A review,” Sep. 01, 2024, Elsevier B.V. doi: 10.1016/j.fraope.2024.100169.
S. Kapoulea, C. Psychalinos, A. S. Elwakil, and M. S. Tavazoei, “Power-law compensator design for plants with uncertainties: Experimental verification,” Electronics (Switzerland), vol. 10, no. 11, Jun. 2021, doi: 10.3390/electronics10111305.
B. Ji, J. Xu, Y. Liu, P. Fan, and M. Wang, “Improved YOLOv8 for small traffic sign detection under complex environmental conditions,” Franklin Open, vol. 8, Sep. 2024, doi: 10.1016/j.fraope.2024.100167.
X. Dong, S. Yan, and C. Duan, “A lightweight vehicles detection network model based on YOLOv5,” Eng Appl Artif Intell, vol. 113, p. 104914, 2022, doi: https://doi.org/10.1016/j.engappai.2022.104914.
M. Majumder and C. Wilmot, “Automated Vehicle Counting from Pre-Recorded Video Using You Only Look Once (YOLO) Object Detection Model,” J Imaging, vol. 9, no. 7, Jul. 2023, doi: 10.3390/jimaging9070131.
V. Singh, S. K. Sahana, and V. Bhattacharjee, “A novel CNN-GRU-LSTM based deep learning model for accurate traffic prediction,” Discover Computing, vol. 28, no. 1, Dec. 2025, doi: 10.1007/s10791-025-09526-0.
C. Gheorghe, M. Duguleana, R. G. Boboc, and C. C. Postelnicu, “Analyzing Real-Time Object Detection with YOLO Algorithm in Automotive Applications: A Review,” 2024, Tech Science Press. doi: 10.32604/cmes.2024.054735.
M. Gupta, H. Miglani, P. Deo, and A. Barhatte, “Real-time traffic control and monitoring,” e-Prime - Advances in Electrical Engineering, Electronics and Energy, vol. 5, Sep. 2023, doi: 10.1016/j.prime.2023.100211.
C. McCarthy, H. Ghaderi, F. Martí, P. Jayaraman, and H. Dia, “Video-based automatic people counting for public transport: On-bus versus off-bus deployment,” Comput Ind, vol. 164, Jan. 2025, doi: 10.1016/j.compind.2024.104195.
R. Murendeni, A. Mwanza, and I. C. Obagbuwa, “Using a YOLO Deep Learning Algorithm to Improve the Accuracy of 3D Object Detection by Autonomous Vehicles,” World Electric Vehicle Journal, vol. 16, no. 1, Jan. 2025, doi: 10.3390/wevj16010009.
X. Yu, P. Wang, and Z. Zhang, “Learning-based end-to-end path planning for lunar rovers with safety constraints,” Sensors (Switzerland), vol. 21, no. 3, pp. 1–17, Feb. 2021, doi: 10.3390/s21030796.
R. Ventura, S. Roussou, A. Ziakopoulos, B. Barabino, and G. Yannis, “Using computer vision and street-level videos for pedestrian-vehicle tracking and behaviour analysis,” Transp Res Interdiscip Perspect, vol. 30, Mar. 2025, doi: 10.1016/j.trip.2025.101366.
Additional Files
Published
How to Cite
Issue
Section
License
Copyright (c) 2025 Pratomo Setiaji, Wiwit Agus Triyanto, Maulin Nurhaliza

This work is licensed under a Creative Commons Attribution 4.0 International License.