1 Introduction

The enormous number of automobiles on the roads in smart cities makes traffic congestion a severe problem. A traditional traffic management system adjusts the green light's duration based on the average traffic volume at the junction. Enhancing and improving vehicle management systems can be achieved through various methods, including infrastructure upgrades, public transportation expansion, traffic enforcement, education initiatives, and smart parking solutions. However, effectively managing road traffic issues often necessitates the implementation of a smart traffic management system (STMS) [1]. These systems utilize advanced technologies such as artificial intelligence, machine learning, and real-time data analytics to optimize traffic flow, reduce congestion, and enhance overall efficiency on the roads. By dynamically adjusting traffic signals, analyzing real-time traffic data, and employing predictive modeling techniques, STMS can revolutionize how traffic is managed in urban environments. Indeed, considering their extensive usage, traditional traffic signal systems sometimes confront numerous well-known issues in many nations, even industrialized ones. Here some potential research gaps are included in the field of smart traffic management systems:

  1. (a)

    Conventional traffic signal systems with fixed timing could be more efficient at managing traffic signal timing at road junctions. Signal timings that are set rather than dynamically altered depending on real-time traffic circumstances may have several negative implications, including increased wait time, traffic congestion, air pollution, and safety issues.

  2. (b)

    In junctions, the proportion of time allotted to each route is fixed, irrespective of the volume of traffic or flow rate. Because time is not distributed in the real-time traffic scenario, this results in inefficient traffic flow. Certain times of the day may see more traffic on particular routes than others, necessitating a longer time to clear the congestion. However, this capability is not available with a regular traffic light.

  3. (c)

    Conventional traffic management systems depend on permanent infrastructure, such as traffic signals, signs, and cameras, to control traffic flow and enforce laws. While these systems may adequately manage regular traffic scenarios, they generally need help handling dynamic occurrences such as cars traveling the wrong routes or participating in reckless driving. In circumstances where a vehicle travels the wrong route or participates in reckless driving, standard traffic control systems may not be able to react in real-time or effectively handle the problem.

Based on the previously described issues of the conventional traffic management system, it is evident that there is a tremendous need to enhance its functioning by giving it some intelligence to allow dynamism and adaptability. Adaptive traffic signal control provides a technique that modifies traffic lights in real time depending on traffic patterns. The technology employs sensors to determine the number of cars on the route and changes traffic lights accordingly. Adaptive traffic signal management may minimize congestion, enhance traffic flow, and cut travel times. In addition to improving traffic flow and adaptable lane management, smart traffic control systems apply intelligent route optimization to handle dynamic occurrences such as vehicles choosing the wrong direction or participating in reckless driving.

The precise research contributions are:

  • Providing a self-adaptive traffic control system algorithm (TCSA) approach for controlling traffic lights in real-time scenarios, which relies on real-time traffic flow evaluation and monitoring.

  • In a sophisticated traffic management system, we design a framework based on Line_1 and Line_2 approaches with three imaginary lanes. The rules are meticulously designed to ensure safety, efficiency, and a smooth traffic flow.

  • The entire dataset has been uploaded to GitHub for further research work in the field of traffic optimization.

Machine learning for dynamic road traffic management in urban areas aims to reduce traffic congestion, improve road safety, optimize resource allocation, integrate public transportation systems, and provide real-time traffic information and individual direction. Smart traffic management systems may solve these difficulties using sophisticated machine learning methods to build more efficient, sustainable, and livable urban transportation networks.

The proposed work is self-adapting TCSA approach for traffic optimization. The solution indeed outlines a promising approach to addressing the challenges in traffic management using machine learning, specifically the YOLO object detection algorithm. By leveraging real-time images from traffic signals and processing individual images rather than entire video streams, the solution aims to be more efficient in terms of computational resources and time [2]. Enhancing traffic optimization algorithms with predefined traffic rules is a crucial step towards making traffic management systems more intelligent. By incorporating speed limits, lane regulations, traffic signal timing, and right-of-way rules, the system can better allocate resources and prioritize traffic flow. Utilizing computer vision techniques, possibly in combination with machine learning algorithms, to track objects in real-time video feeds from traffic cameras is a powerful approach. Object tracking algorithms can help monitor the movement of vehicles, pedestrians, and cyclists, providing valuable data for traffic management decisions. Analyzing the behavior of tracked objects to determine whether they are following or disobeying traffic rules is a significant advancement. By detecting actions such as running red lights, speeding, illegal lane changes, and pedestrian jaywalking, the system can take proactive measures to improve safety and efficiency on the roads. Combining image processing and machine learning technologies for controlled traffic clearing at intersections represents an innovative approach to traffic management. This integration allows for real-time analysis of traffic conditions and efficient decision-making processes. The suggested method establishes traffic clearing at road intersections using the object detection model (YOLOv3) and artificial intelligence neural networks for single and multiple image processing. These framework encompassed metrics such as rapid and mean average precision (mAP), processing time, high accuracy, intersection over union (IOU) values, and speed. By optimizing these metrics, we aimed to achieve superior performance in object identification tasks, ensuring efficient and accurate detection of objects in real-time scenarios. We examined the "on-time period green light" based on YOLO's advice to determine the best traffic-clearing strategy. The "on" duration of the green light is calculated by considering many variables, such as the number of two-wheelers (TW) and four-wheelers (FW) on the road, its breadth, and the moment when vehicles pass a junction. In the context of intelligent traffic management, computer vision systems can analyze real-time video feeds from traffic cameras to monitor traffic flow, detect congestion, and identify traffic violations such as running red lights or illegal lane changes. These systems can provide valuable data for optimizing traffic flow and enhancing road safety by tracking moving objects such as vehicles, pedestrians, and cyclists. Similarly, in security surveillance applications, computer vision technologies are essential for monitoring and identifying moving objects in real-time. By detecting suspicious activities or unauthorized intrusions, these systems can alert security personnel and take appropriate action to mitigate potential threats. This study is organized as follows: In Section 2, which summarizes the relevant work in this area, we start by looking at an overview of the current literature. In Section 3, we explore the complexities of our traffic simulation and proposed framework, which are critical parts of our framework for intelligent traffic management. The system architecture, methodological foundation, and algorithmic nuances of our proposed system are all explained in Section 4. Next, we provide a thorough simulation and analysis of the performance metrics obtained from our innovative strategy in Section 5. This section explains how well and efficiently our system manages various traffic situations. Section 6 summarizes our study's conclusions and future developments in intelligent traffic control systems as we wrap up our discussion.

2 Related work

In numerous regions, traffic congestion poses a significant concern. With countless objects occupying roads on a daily basis, managing traffic becomes increasingly difficult. Traffic management systems researchers have conducted extensive studies to enhance flexibility, intelligence, and self-adaptability. They have installed cameras at highways and intersections to actively monitor and enforce autonomous penalties for traffic regulation violators. While most traffic intersections use a fixed-time green light cycle for traffic control, this approach has drawbacks, such as ineffective traffic congestion reduction. The standard time-limited signal system functions well when traffic flow is nearly identical in all four directions. However, advanced strategies are required to address more complex traffic scenarios. During the daytime, traffic tends to be heavier in one direction compared to others. However, the existing traffic management method lacks intelligence, leading to unnecessary waiting times even when there are no vehicles on the opposite side. This inevitable waiting period can cause frustration among drivers, potentially resulting in rule infractions and accidents. Additionally, it contributes to increased fuel usage and environmental pollution. To address these issues, several research studies have focused on tackling traffic congestion and managing traffic flow more effectively. One advanced approach involves making traffic signals responsive to current traffic patterns. By utilizing real-time data on traffic volume and demand, STMS can adjust signal timing dynamically. This adaptive approach aims to minimize delays and optimize traffic flow, ultimately improving overall traffic efficiency and reducing the negative impacts of congestion on both drivers and the environment [3].

A sophisticated traffic management system employs a blend of automated mechanical and electronic devices to regulate traffic flow effectively. This includes sensors for monitoring traffic volume and vehicle movements, automated signal controllers adjusting timing based on real-time data, and potentially mechanical barriers or gates for access control [4]. By leveraging advanced technology like AI and machine learning, the system intelligently adapts to changing traffic conditions, optimizing flow in real-time. Benefits encompass reduced congestion, improved safety, and enhanced transportation network efficiency. However, challenges such as cost, technical complexity, and privacy concerns related to data processing and collection need addressing [5]. Analyzing traffic management systems involves a structured approach that considers various factors such as technology, functionality, and objectives. This comprehensive analysis covers a broad spectrum of topics, ranging from conventional methods to cutting-edge approaches. It delves into the strengths and limitations of each system while also exploring emerging trends in the field. [6]. The main body of the paper likely details the methodology for developing and implementing a fuzzy inference system for traffic light control, including defining linguistic variables and establishing fuzzy rules. Simulation results and performance metrics likely demonstrate the system's superiority over traditional methods [7].

The article on smart cities and smart roads likely emphasizes integrating advanced technology into road infrastructure to address challenges like congestion and pollution while enhancing safety and mobility. It underscores benefits like intelligent transportation systems and human-centric features, discussing challenges, opportunities, and future directions [8]. Research on urban challenges discusses the importance of efficient traffic management systems for addressing congestion, enhancing safety, and promoting sustainable mobility. It contributes valuable insights for policymakers, planners, and transportation professionals [9, 10]. Technology integrations like YOLO for object detection and IoT-based traffic control systems showcase efficient monitoring, congestion detection, and real-time management, offering practical solutions to traffic issues [11]. The paper on the YOLOv3 algorithm highlights its high precision and near-real-time performance in detecting traffic participants across varied driving conditions, showcasing adaptability and effectiveness [12]. Table 1 compares the many sorts of work scholars do on various platforms and their applications. All traffic management systems accept video data as input and analyze it to extract information about the traffic situation.

Table 1 Summary of current studies and applications

The article proposes leveraging machine learning-driven technology, specifically the YOLOv3 object detection technique, to address the challenges associated with processing traffic stream videos for traffic management. YOLOv3 is known for its ability to detect objects in real-time images efficiently. The article suggests using YOLOv3 to determine the duration of green lights based on the number of vehicles detected, potentially optimizing traffic flow in real-time. This approach could potentially offer a quicker, more accurate, and more cost-effective solution compared to traditional methods of processing video streams for traffic management [25, 26]. Table 2: Studies that examine the conceptual aspects of multiple YOLO-based machine learning-driven models for object recognition and compare different versions of the YOLO (You Only Look Once) framework. These studies consistently focus on better comprehending the influence of various design decisions on performance metrics involving velocity, precision, and efficiency.

Table 2 Summary of current studies and applications of various YOLO-based machine learning models

3 Traffic simulation and proposed framework

Using state-of-the-art vehicular traffic flow modeling, the interaction between drivers, vehicles, and infrastructure may characterize traffic dynamics. Hence, this self-adaptive intelligent traffic prediction model combines many data: driver behavior in automobile acceleration, street agglomeration, travel speeds, pedestrian movement, and road sign placement. It is desirable to obtain the optimum time to cross junctions by analyzing this data to alleviate traffic delays. Simulation models have been developed primarily using data collected from various traffic monitoring sensor networks. These models enable the prediction of traffic evolution and can identify intersections with the highest risk of obstruction. Setting the proposed model parameters' values to ensure the simulation matches the traffic statistics is worth noting. The culmination of this procedure is a calibrated model capable of predicting traffic flow, commonly referred to as model calibration. Figure 1 depicts a schematic depiction of a vehicular traffic flow model with all these factors.

Fig. 1
figure 1

State-of-the-art vehicular traffic flow modeling

The proposed self-adaptive smart traffic optimization system consists of several functional blocks depicted in Fig. 2. A sophisticated traffic management system that utilizes computer vision techniques like YOLOv3 for object detection and classification, along with algorithms to control traffic signals and analyze vehicle flow patterns. This system can be highly effective for monitoring traffic conditions, managing signal timings, and detecting abnormal behaviors like wrong-way driving. Here's a breakdown of the components and their functions:

  • Smart Traffic Camera: Traffic cameras capture images of the road network, which are then processed by the system.

  • Traffic Monitoring and Control System: This system receives input from the traffic cameras and processes it using the YOLOv3 model. It then analyzes the detected objects to monitor traffic conditions.

  • Pre-Trained Model (YOLOv3): YOLOv3 is a deep learning-based model capable of detecting and classifying objects in images. In this context, it's used to identify vehicles and potentially other objects relevant to traffic management.

  • Intelligent Approach: TCS algorithm uses the information gathered from the traffic monitoring system to determine the optimal timing for traffic signals. It computes the time 't' for each signal phase, deciding when to switch from red to green lights at intersections.

  • Object Tracing: These are virtual representations of the paths taken by vehicles as they move through the road network. The system creates and analyzes these flow lines to understand the direction and volume of traffic flow.

  • Statistical Analysis and Result Inference: By examining the flow lines, the system can identify instances where vehicles are traveling in the wrong direction. This could indicate a serious safety hazard, and appropriate actions can be taken, such as alerting authorities or adjusting signal timing to prevent further incidents.

Fig. 2
figure 2

The proposed framework of self-adaptive smart traffic optimization model

4 Proposed methodology and algorithm

4.1 System architecture

The system necessitates the installation of four different cameras, each at the top of the road that intersects at the traffic road junction (Fig. 3). These cameras send their acquired pictures to an integrated controller. This controller counts the number of traffic objects, including TW and FW, by analyzing the real-time photographs. Subsequently, the timing of the green signal is modified to account for the number of objects detected.

Fig. 3
figure 3

The placement of self-adaptive smart traffic cameras: top view

Smart cameras have been installed atop traffic lights at many intersections, requiring connectivity to a controller. As depicted in Fig. 4, cameras typically cover only one side of the road. The controller might carry out the following operations:

  1. 1.

    Specify that the camera snaps a picture of the traffic scenario.

  2. 2.

    The number of objects in the camera's input images should be counted.

  3. 3.

    To determine how long the green light should be on at a particular position based on the number of vehicles.

  4. 4.

    Turn on the red light of the other signals and the green light of the corresponding signal.

Fig. 4
figure 4

The placement of self-adaptive smart traffic cameras: side view

4.2 Data sets

The network has to be trained beforehand using the potential input set to get more accurate predictions. Before being put through actual testing, the YOLOv3 model was trained using many traffic junctions and vehicle images. The official Incubation Center Smart City of State Govt. MP, a public research and development agency located in Madhya Pradesh, India, provided the dataset used in this study, referred to as "Traffic Data." Three different picture types are included in the mobility aids dataset: RGB images, perfect depth images, and depth map images. Five distinct classes make up this dataset: persons with walking frames, transport items, TW objects, FW objects, and traffic lanes at intersections. Every image has tags in it that correspond to the image information found in the annotation file. It contains category information for every recognizable item (TW and FW) in the picture. The five categories listed above comprise the category information, and four coordinate points (x_min, x_max, y_min, y_max) are often used to convey the location information. Furthermore, we computed the evaluation indicators in the test set. We applied our object identification model to the standard test set, which consists of more than 1000 images and their corresponding tag data.

4.3 Platform

The TensorFlow framework developed the suggested system based on multiple object detection and tracking using CNN. The laboratory setting served as the training and deployment site for our concept. The system configuration is TITAN XP (GPU), with 64 GB of RAM, an Intel Xeon (R) CPU (processor), and a 64-bit operating system. The model needs an image with an input size of 416 × 416, 100 training iterations on the traffic dataset, an initial CNN 0.001 learning rate, and a 0.9 momentum factor. Furthermore, this research makes use of the size and quantity of anchors—116 × 90, 156 × 198, 373 × 326), (30 × 61), (62 × 45), and (59 × 119)—obtained by k-means clustering in Yolo v3. The predefined IOU's threshold is 0.76.

4.4 Traffic control system algorithm

Driving objects are approaching from the driving side of the signal. Correct positioning of the cameras is crucial to prevent objects from overlapping in the picture, as overlapping can lead to erroneous detection results. Figures 5 and 6 depict the various types of photos captured by the traffic cameras and object detection and analyzed by the prediction model. The amount of vehicle overlapping is significant in the images on the left, making them unsuitable for processing. On the other hand, the two images on the right half of Fig. 6 demonstrate the vehicle's accurate distribution and slight overlapping. As a result, the approach will benefit significantly from these images.

Fig. 5
figure 5

Object detection and analysis for traffic at cross-road (Training Data Set A)

Fig. 6
figure 6

Object detection and analysis for traffic at cross-road (Training Data Set B)

The study uses OpenCV to count the automobiles in the input picture. OpenCV is a C +  + and Python-based image processing library. OpenCV [7] includes modules for object detection using a variety of approaches, and OpenCV is used in this study. The cdn [43] module is efficiently used to predict and count the number of objects. The YOLO v3 model receives the input picture through OpenCV [44, 45]. The method splits the image into regions and predicts bounding boxes and probabilities for each area using a single neural network applied to the entire image. The anticipated possibility is that these bounding boxes are weighed. Each object recognized in the picture produces a list of bounding box coordinates. The number of vehicles in the returned list would represent the number of objects [46]. Most studies employ the same lane clearance time for TW and FW objects. However, FW objects take longer to start and leave the signal in a real-time scenario than TW vehicles. As a result, it is crucial to factor in the time it takes to depart from the signal intersection [47, 48]. Figure 7 illustrates the entire process of traffic optimization, encompassing all stages and the processing of data captured by traffic cameras. This comprehensive approach ensures effective traffic management and optimization based on real-time data analysis.

Fig. 7
figure 7

Traffic Optimization Stages and Data Processing

Differently, FW and TW objects contribute to the processing time required to clear the road traffic in this proposed work. The controller then assigns the on-time green light after approximating the true time period based on the number of vehicles (TW and FW) and their timings to clear the road lane, which is symbolized by the text ‘t’. The time ‘t’ is calculated using Eq. (1).

$$\begin{array}{cc}t=\lceil\frac{TW}{a}\rceil*n+\lceil\frac{FW}{b}\rceil*m& //\mathrm{ time\;calculation}\end{array}$$
(1)

where,

TW:

stands for the total number of two-wheelers in the data.

FW:

is denoted by the number of four-wheelers/objects in the data.

n:

Denotes the number of seconds to clear a single two-wheeler.

m:

Denotes the time it takes to clear a single four-wheeler.

a:

The maximum number of TW objects available in the whole width of the road.

b:

Maximum number of FW objects available in the whole width of the road.

A vehicle's clearing time is determined by measuring how long it takes to pass the stop line from where it is currently standing. Consequently, the constant parameters n and m are determined by real-time observation of the traffic road junction. The measured values for n and m are 4.2 and 6.46 s, respectively. We adjusted the parameter value of n to 4 s because a driver's response time in most scenarios is more significant than 2 s.

More factors are needed to determine constants a and b, such as road width (Wroad), width of a TW (W2), width of a FW (W4), and the ground (G) spacing between any two objects. For different traffic crossroads, the width of the road may vary. We are focusing on the most prevalent scenario right now.

Wroad = 40 ± 5 feet, W2 = 3 feet, W4 = 7 feet, G = 2 feet, and finally, Eqs. (2) and (3) determine the values of a and b.

$$\begin{array}{cc}{\text{a}}=\lfloor \frac{{W}_{road}}{{W}_{2}+ G}\rfloor & //\mathrm{counting\;the\;most\;two}-\mathrm{wheeled\;objects\;that\;can\;fit\;on\;the\;entire\;width\;of\;the\;road}\end{array}$$
(2)
$$\begin{array}{cc}{\text{b}}=\lfloor \frac{{W}_{road}}{{W}_{4}+ G}\rfloor & //\mathrm{counting\;the\;most\;four}-\mathrm{wheeled\;vehicles\;that\;can\;fit\;on\;the\;entire\;width\;of\;the\;road}\end{array}$$
(3)

For, road width = 35 ft.

$$\begin{array}{cc}{\text{a}}=\lfloor \frac{35}{3+2}\rfloor =\lfloor 7.0\rfloor =7;& {\text{b}}=\lfloor \frac{35}{7+2}\rfloor =\lfloor 3.88\rfloor =3\end{array}$$

For, road width = 40 ft.

$$\begin{array}{cc}{\text{a}}=\lfloor \frac{40}{3+2}\rfloor =\lfloor 8.0\rfloor =8;& {\text{b}}=\lfloor \frac{40}{7+2}\rfloor =\lfloor 4.44\rfloor =4\end{array}$$

For, road width = 45 ft.

$$\begin{array}{cc}{\text{a}}=\lfloor \frac{45}{3+2}\rfloor =\lfloor 9.0\rfloor =9;& {\text{b}}=\lfloor \frac{45}{7+2}\rfloor =\lfloor 5.0\rfloor =5\end{array}$$

There is a high probability that many automobiles will be at the intersection and move slowly, starving the automobiles on the other side of the road. It is essential to set a maximum time restriction and determine the least practical number of objects within the time range the previously given algorithm predicted. Consequently, Eq. (4) provides the actual time period for computing the duration of the green light.

$${t}_{{\text{actual}}\_{\text{time}}}=\mathrm{min}({\text{t}},\mathrm{ MAX}\_{\text{GREEN}}\_{\text{TIME}})//{\text{t}}-\mathrm{Actual\;time\;for\;max\;of\;green\;light\;time}$$
(4)

To assess the worst-case scenario result of Eq. (1), where all automobiles are four-wheelers (FW), we need to determine the MAX_GREEN _TIME. Given that we cannot remove more than 30 FW vehicles from any one side of the intersection and assuming no TW, we can set TW = 0 and FW = 30 in Eq. (1) to calculate the expected time:

For road width = 35ft

$${\text{t}}=\lceil \frac{0}{7}\rceil *4.2+ \lceil \frac{30}{3}\rceil *6.46=64.6\,\mathrm{ sec}$$

For road width = 40ft

$${\text{t}}=\lceil \frac{0}{8}\rceil *4.2+ \lceil \frac{30}{4}\rceil *6.46=48.45\,\mathrm{ sec}$$

For road width = 45ft

$${\text{t}}=\lceil \frac{0}{9}\rceil *4.2+ \lceil \frac{30}{5}\rceil *6.46=38.76\,\mathrm{ sec}$$

With a minimum road width of 35 feet, we utilized the worst-case scenario, corresponding to a MAX_GREEN_TIME of 64.6 s, for future calculations. Figure 8 depicts Eq. (1) concerning the number of objects in three different kinds of scenarios: (1) when traffic only has TW (TW = 30 & FW = 0), (2) when traffic only has FW (TW = 0 & FW = 30), and (3) when traffic has both TW and FW in the same ratio (TW = 15 & FW = 15). The curve with a MAX_GREEN_TIME of 64.6 s approaches a flat irrespective of the proposed three conditions, as shown in Fig. 8.

Fig. 8
figure 8

Compute the time for the green light, which has a peculiar behavior

To study the worst-case situation further, we only assessed FW vehicles and computed clearance times. It is calculated that it will take 775 s for all 120 FW objects in traffic to clear. The round time shown in Fig. 9 denotes the time a vehicle (TW and FW) is granted a second clearing chance after the MAX GREEN TIME threshold time has been reached.

Fig. 9
figure 9

In the worst-case scenario, total traffic clearance time is proportional to the number of vehicles

For each of the four directions that cross at the intersection:

  1. 1.

    Take the input as an image before turning on the green light for two seconds.

  2. 2.

    Prepare the picture for vehicle detection by preprocessing it.

  3. 3.

    Count the (a) TW and (b) FW in the picture using object detection.

  4. 4.

    Using the numbers in the equation, calculate the total time ‘t’.

  5. 5.

    Continue to have the green light on the entire time ‘t’.

  6. 6.

    Repetition of step 1 for the following camera.

4.5 Object tracing algorithm

As described in this section, estimating vehicle trajectory involves calculating the difference in pixels within a range of XF-frames. Here, 'F' represents the number of frames used to monitor a specific object. This difference in pixels is then analyzed to determine the flow direction of a tracked object. First, we establish the object's starting coordinates (X0, Y0) in the frame (F0) by computing its beginning location from the bounding box of a detected automobile. As the automobile drives, the starting coordinates' area changes from frame to frame. Therefore, for each frame, we determine the pixel difference between (X1, Y1) and (XN, YN), where X1, Y1 denotes an object's (Initial + 1 Frame) X0 + 1 location in a frame (F1) and XN and YN in a frame (FN). Let us use six frames as an example and utilize them for tracking. The difference in pixel position would be Do = X5—X1, where Do is the direction of the object. The second frame is the initial starting point, while the sixth is the final stopping point. The ID assignment phase is carried out on the first frame when the automobile is spotted.

Algorithm for object tracing

figure a

4.6 Two-line approach framework

We implemented the two-line method using three fictitious lanes to verify the proper direction of objects. The concept is clear and practical, illustrated by drawing two lines, Line_1 and Line_2, along with three simulated lanes on the video frame, as depicted in Fig. 10.

Fig. 10
figure 10

Two-line approach framework for traffic flow at traffic junctions

Following the initial setup, we crop the video frame to focus on the desired area of interest. Traffic is directed to pass through the intersection of Lines 1 and 2, denoted by red lines. As shown in Fig. 11, we provide an innovative traffic rule based on a two-line technique to enhance the efficiency of traffic movement.

Fig. 11
figure 11

Defined Framework for traffic flow and validation of directions at traffic junctions

4.6.1 Assigning object IDs

Vehicle Unique IDs are stored in a list upon arrival at Line_1 or Line_2 and removed when passing through the traffic area.

4.6.2 Designated traffic lanes

  • Line_1: Reserved for vehicles making left turns or proceeding straight from their starting point.

  • Line_2: Exclusively designated for vehicles moving straight ahead from their starting point or executing right turns.

4.7 Wrong-Directions and reckless driving object detection

The object crosses both Line_1 and Line_2 simultaneously; it is identified as traveling in the wrong direction, triggering a warning signal. Additionally, objects with an angle exceeding 60 degrees concerning a particular Line_1 or Line_2 are flagged as engaging in reckless driving, as shown in Fig. 12.

Fig. 12
figure 12

Reckless driving angle (a) deviation > 60* for each line

Figure 13 illustrates how the location of the moving object changes throughout N = 4 frames. The green box represents the object's displacement across each frame. In this instance, the word objects ID indicates that the object travels from right to left or left to right in the video.

Fig. 13
figure 13

Displacement of an object within N = 4 frames

5 Results and discussion

To assess the effectiveness of our effort, we carried out three different sorts of experiments. The first included 45 genuine real-time traffic photos from the two main junctions of Jabalpur (Shastri Bridge), Madhya Pradesh, which have been used to train the YOLOv3 object identification model. We have taken nine real-time traffic images preserved from the training data set. Table 2 displays the results of the test photographs. The second included evaluating the accuracy of object identification in various illumination scenarios, and the third involved wrong-way driving detection. We have made a real-world camera available and used it to simulate an automobile traveling in the opposite direction.

5.1 Objects detection and counting validation

First, we collected data from smart cameras mounted at traffic intersections to test the performance of object recognition. The numbers of objects in the image data set are manually computed. We then routinely choose a picture dataset with various time intervals. We selected a range of time windows, including dawn, dusk, and nighttime hours. We determined the mean average precision (mAP) with an IOU threshold of more than 0.76 to assess detection accuracy.

$$\upmu = \frac{No.of\;Predicted\;Objects}{Actual\;No.of\;Objects\;in\;Image\;DataSet}\ge 0.76$$

To establish the locations of the objects in each picture frame, we manually counted the number of objects inside the specified intervals and marked them. Only when the IOU rate was over 0.76 were the objects regarded as having been detected. Table 3 shows that the detection system recognized objects at various time slots with an average mAP of 88.51%. We tested our program, focusing on accuracy and speed, with an eye on its intended use in real-time traffic events. Despite the program being created to identify just a single class, we acquired superior performance compared to the creators of the classic YOLOv3 model in terms of the mAP score.

Table 3 Results of object detection and counting obtained from training sample data

As shown in Fig. 14, YOLOv3 outperforms the original YOLO model regarding processing time. Changes in network architecture, such as convolutional layers and feature pyramid networks (FPN), which enable speedier inference with respectable accuracy, enable this development. Compared to YOLOv3, the original YOLO model's processing time is noticeably slower. Despite being the first to use real-time object recognition, YOLO's processing speed may not be as fast as that of more recent versions because of architectural constraints. Regarding object identification tasks, YOLOv3 outperforms the original YOLO model's accuracy. This improvement is ascribed to developments in training methodologies, multi-scale prediction, and feature pyramid networks, which lead to more accurate object localization and classification. Although YOLO provides acceptable accuracy, its single-scale prediction and network design restrictions may limit its ability to recognize tiny objects and cases with heavy occlusion. YOLOv3 has better object recognition performance, particularly when objects have different sizes, orientations, and levels of occlusion. The original YOLO model remains helpful for object detection across different environments and is praised for initiating real-time object identification. However, its performance may be restricted, especially in challenging scenarios involving tiny objects or severe occlusion. In comparison, YOLOv3 displays higher performance in processing speed, accuracy, and object-detecting capabilities. Its network design and training procedure improvements identify it as a favored alternative for real-time object recognition applications needing high accuracy and robustness.

Fig. 14
figure 14

Comparative analysis of the YOLO model with other alternative object detection models

Table 4 depicts the evaluation results of the proposed model, encompassing a confusion matrix and significant performance metrics like accuracy, recall, precision, and F1 score. The confusion matrix offers a granular breakdown of the model predictions compared to the actual ground truth across multiple image data sets.

Table 4 The confusion matrix is used to evaluate the performance of training datasets

5.2 Traffic rules violator’s objects

The system's output for the detection portion was the total number of objects that passed through each lane of the traffic junction (the suggested framework) in a video frame. Roadside smart cameras record videos with a resolution of 1280 × 720 pixels. We saw moving objects that were traveling in the incorrect direction at the same time, simultaneously crossing the right and left lines. Our technology also has object-detection capabilities. Additionally, our system recognizes an object if it deviates more than 60 degrees from the line's centroid position, indicating reckless driving. The images of the objects inside the video frame shown in Fig. 15 have been captured. Objects outlined in orange have entered the designated area in the incorrect direction, while those highlighted in dark green are behaving recklessly while traversing the road. To safeguard their identities, the vehicle license plates have been obscured.

Fig. 15
figure 15

Wrong-Turn taken and reckless driving objects are detected

The segmentation results for object driving direction and the accuracy (confusion matrix) of reckless driving identification that we acquired from our experiment are shown in Table 5. Our system correctly identified objects moving in the incorrect direction. In particular, every occurrence of a car traveling in the incorrect direction in each of the four video modules was correctly recognized. The accuracy rate of the suggested framework is outstanding, averaging around 90.45%.

Table 5 The confusion matrix and the results of wrong-turn-taken objects and reckless driving objects from the training datasets

6 Conclusions and future work

Self-adaptive road traffic management encompasses a range of strategies to reduce traffic congestion's occurrence and adverse effects, including minimizing delays, reducing object waiting times, and recognizing wrong turn-taking objects. Additionally, it involves improving the efficient flow of traffic on road networks and dynamically allocating traffic flows to optimize efficiency. Through these measures, road traffic management seeks to enhance overall traffic effectiveness and mitigate congestion-related challenges for motorists and the community. The proposed algorithm aims to optimize traffic flow by reducing vehicle waiting times at traffic junctions and mitigating congestion by managing the flow of vehicles on roads. The system can use the YOLO technique, a machine learning-driven object detection algorithm, to identify and track vehicle objects in real time. An AI-based self-adaptive traffic optimization system can dynamically adjust traffic signal timings based on the current traffic conditions. The approach allows the system to respond in real-time to traffic volume and pattern changes, improving overall traffic flow efficiency and reducing congestion. To determine the optimal duration for green lights, we analyzed various temporal factors, including traffic volume, road width, and intersection processing times. We trained a neural network to enhance vehicle detection accuracy using extensive datasets of authentic traffic images. The method involved integrating two state-of-the-art YOLOv3 methods to effectively monitor and identify objects, particularly vehicles.

Additionally, we developed a novel technique to detect vehicles traveling in the wrong direction. Our experiments, conducted across two simulated scenarios, achieved an average object detection accuracy of 88.43% and a remarkable 90.45% accuracy in tracking vehicles engaging in wrong turns or reckless driving behaviors. Our technique proved highly effective in identifying vehicles moving in the incorrect direction, contributing to safer, more efficient traffic management and hardware advantages compared to traditional traffic-clearing strategies. By leveraging AI-based technology and innovative methodologies, our solution provides a cost-effective, efficient means of optimizing traffic flow and enhancing road safety. Upcoming research will explore using cameras positioned at higher elevations to provide panoramic and comprehensive road coverage. This approach aims to improve the accuracy of the data collected, enabling more precise detection and tracking of vehicle objects. By expanding the coverage area and leveraging advanced camera technologies, we anticipate significant improvements in the effectiveness and reliability of our traffic management system.