Traffic Analysis System

 Status : Completed

Tags: opencv python tkinter yolov8



AIM

To analyze various aspects of Indian traffic and derive required parameters from its analysis which helps in calculating the quantitative requirements of roads.


COMPONENTS AND TECHNOLOGIES USED

  • python

  • opencv

  • tkinter

  • yolov8


OVERVIEW

This is a project based on computer vision, ML and DL, it is aimed to analyze various parameters of Indian traffic and facilitates required by the civil engineers to derive required parameters from traffic analysis which helps in calculating quantitative requirements for road upgradation and traffic flow analysis by avoiding laborious work and also for various other different applications.

 

In this project the traffic analysis is divided into two parts:

  • Traffic flow analysis
  • Spot Speed analysis of traffic

 

  • Traffic flow analysis

Here the volume of the traffic flow is analyzed and peak hour factor is measured

  • Spot Speed analysis of traffic

Here the rate of the traffic flow is analyzed and percent cumulative frequency distribution graph is plotted from collected data


 

  • Cumulative frequency distribution graph and peak hour factor are measured using algorithms.

Autonomous Traffic Analysis System is a software program that will take real-time vehicle data from the camera and convert the data into interactive charts and calculate required parameters like percentile speed and other important parameters.

The data collected for traffic volume studies and spot speed analysis which facilitates in determining the :

  1. Magnitudes, classifications and the time and directional split of vehicular flows.
  2. Proportions of vehicles in the traffic stream.
  3. Hourly, daily, yearly and seasonal variation of vehicular flows.
  4. Flow fluctuation on different approaches at a junction or different parts of a    road network system.
  5. The structural and geometric design of pavements, bridges and other highway facilities.
  6. Intersection design.
  7. Improvement of roadway operating conditions.
  8. Traffic signal design.
  9. Economic feasibility.

etc.

 

Tech Stack:

Python

  • OpenCV
  • Matplotlib
  • Numpy
  • Pandas
  • Tkinter
  • Supervision
  • Haar Cascade
  • YOLOv8

 

Approach:

  1. Selecting the Model

There are multiple methods and models to detect the objects so selecting the most appropriate model is an essential task for a project. YOLO V8 has been used in the project which works on neural networks and the recent 8th version has best efficiency when compared to other models available in the community. Haar Cascade is another ML based model which is helpful in detecting objects but the efficiency is less when compared to YOLO.


 

  1. Vehicles detection:

 

Detected vehicles are enclosed in a bounding box.


 

  1. Differentiating the different vehicles:

 

Detected vehicles are given ID’s and their type is also detected and shown over the bounding box. 


 

  1. Categorizing the Vehicles:

 

Detecting and differentiating whether the vehicle detected is a car,   bike, bus or a truck.

  1. Detection of Required Objects

The Indian vehicles are classified into 4 categories:

  • Two wheeler
  • Three wheeler
  • Four wheeler
  • Bus (mini and full)

YOLO object detection model for detecting vehicles and a custom implementation of the BYTE Tracker algorithm for tracking the detected vehicles. The video is read frame by frame using the supervision library, and the detection and tracking algorithms process each frame.

  1. Speed detection

The speed of the vehicles has to be detected in spot speed analysis. In speed detection, the Haar Cascade method is used to detect the vehicles and then we are measuring the time taken by the vehicle between any two points on the road. Since we already know the distance between the two points so speed=distance/time. This algorithm reads a video file of a traffic scene, detects and tracks vehicles using a Haar cascade classifier and a correlation tracker, and estimates the speed of the vehicles based on their movement between consecutive frames.


 

  1. Traffic flow Analysis 

Traffic Volume is defined as the number of vehicles passing a section of a lane or roadway during a given time interval. Traffic volume studies are conducted to determine the number, movements, and classifications of roadway vehicles at a given location. We count the number of vehicles in a given time interval and then convert them into their respective PCU (Passenger Car Units) which are traffic variables (such as headway, speed, and density) compared to a single standard passenger car and calculate the volume and peak hourly factor and the data can be presented and analyzed by plotting graphs 




 

  1. Spot Speed Analysis

This is a statistical analysis of data we collected from speed detection. In speed detection, we collected the vehicle's number and their speed in an Excel file, now the spot speed Algo. will plot related graphs of the given data. For spot speed analysis we used the matplotlib library of Python.

Graph 1: Speed vs Frequency.

Graph 2: Speed vs Cumulative Frequency.

This analysis will give values like Mean Speed, Median Speed, Mode  Speed, and standard deviation of speeds of vehicles.

  1. GUI

Our GUI has Following features:

  1. An upload button to upload the video we want to analyze.
  2. After uploading the video download button to download the result pdf of the volume study and spot speed analysis.
  3. And lastly, two buttons to see the result videos. One for vehicle detection video and the second for speed detection.

 

Parameters derived:

 

Peak hour factor: 

 

Peak Hour Factor (PHF) is a ratio used to estimate the amount of traffic during the peak hour of a day. It is important in transportation planning and engineering for capacity analysis, traffic signal timing, transit planning, and environmental impact assessment. PHF helps identify bottlenecks, optimize traffic flow, and inform decisions about roadway improvements and public transportation services.

 

Percentile speed:

 

Percentile speed is a measure used in transportation planning and engineering to describe the distribution of vehicle speeds at a particular location or segment of a roadway. It is useful for determining design speed, identifying areas where speed management measures are needed, assessing safety, monitoring performance, predicting traffic flow, comparing roadway designs, and promoting safe driving practices. Incorporating percentile speed data into traffic models helps transportation planners predict the effects of new roadway projects or changes in traffic management measures. Ultimately, percentile speed helps improve roadway safety and efficiency.

 

Problems Faced

  1. Haar Cascade was initially used for detection, but vehicles were detected with less efficiency.
  2. YOLO v8 was chosen as a trusted worldwide model, which did not require dataset collection as it was pre-trained.
  3. However, an unstable Python version caused YOLO v8 to malfunction.
  4. The Python version was changed from 3.11 to 3.9, requiring the downgrade of all other library versions.
  5. Tracker ID was used to ensure unique vehicle identification, as vehicles were detected multiple times.
  6. Parameters varied across different videos, such as orientation, requiring adjustments to the code parameters for accurate speed measurement.
  7. The high-resolution video was found to improve the effectiveness of detection.

 

Applications:

 

The project finds a large spectrum of real-life areas of application

  • To study the type of traffic passing a particular road,  its volume studies and spot speed analysis which facilitates in determining the majority of traffic passing the road, to determine the busiest hours of the road and its traffic density.
  • The speed detection of vehicles can help in maintaining traffic rules and reduce accidents on roads and for surveillance of remote locations.
  • This can also be used as a traffic management system as on busy hours the traffic can be diverted to reduce rush on road.
  • By analyzing the data the road utility can be calculated
  • To update or develop the algorithm to identify the pedestrian traffic and help in calculations required for traffic signaling.

 

Future Scope:

 

The system developed in this project has a lot of potential for future expansion and improvement.

  • It can be upgraded to a multilane System
  • Incorporating advanced image processing techniques to improve the detection of traffic violations and the identification of number plates.
  • Further development of the system's emergency vehicle path planning capabilities, possibly incorporating real-time traffic information to optimize routing and response times.

 

Source Code 

Github:https://github.com/roboclub-mnnit/Autonomous_traffic_analysis_system-2022-23-Project

 

Resources

Python: https://docs.python.org/3/library/tkinter.html

OpenCV: https://docs.opencv.org/4.x/d6/d00/tutorial_py_root.html

Tkinter: https://docs.python.org/3/library/tk.html

YOLO v8: https://github.com/ultralytics/ultralytics

 

Project members:

 

Name

Branch

Registration number

Priyansh Lohiya

Electronics and Communication Engineering

20215109

Aayush Verma

Electronics and Communication Engineering

20215056

Priyanshu Maurya

Electrical Engineering

20212021

Rishi Mishra

Electronics and Communication Engineering

20215096

 

Mentors:

 

Name

Branch

Registration number

Kandukuri Yaswanth

Civil Engineering

20201057

Anurag Gupta

Electronics and Communication Engineering

20195168