AUTOMATED TRAFFIC COUNTING AND CONTROL.

Nilosha Pereira, K.K.P Gayashani, L.G.K.M Gunathunga, N.Y Niluka, A.A.JChinthaka and Gayana Fernando. Sri Lanka Institute of Information Technology Computing (Pvt) Ltd. ...................................................................................................................... Manuscript Info Abstract ......................... ........................................................................ Manuscript History

Road traffic has become one of the main issues in Sri Lanka.Poor infrastructure facilities are unable to handle the increasing traffic and this resulted in generating higher traffic in town areas. Another reason for the road traffic is the poor traffic management systems implemented as well as the poor traffic management by the traffic police. Inexperienced traffic police handling the traffic might sometimes create more traffic rather than decreasing the traffic. Violation of the road rules and regulations also increase the traffic generated on the roads. The valuable time as well as the money spent on fuel is wasted due to this issue. To address this issue following system will first analyse video footage using object detection algorithms and count the number of cars entered into a particular road. Using the output counts prediction algorithm which the system consist will statistically generate a predicted time that the traffic light should be timed. This green time is the optimal time that the traffic light systems should be programmed in order to minimize the road traffic. Key benefits of this system is the reduction of the traffic thus save the valuable time of the citizens and saving the money which spent on fuel. And in the long run pollution of environment in air and sound forms will reduced as well as the increase of the productivity as a country will utilize the limited time due to the system.

…………………………………………………………………………………………………….... Introduction:-
TODAY ROAD TRAFFIC has become a main issue in Sri Lanka.Sri Lankan government uses manual methods to count the number of cars which enter into a road on a particular date and time. Then the road development authority uses this data to time the traffic lights as well as to decide the size of the road project. In many cases traffic light systems are implemented not using statistical data but just numbers entered randomly and it's not based on the location or the traffic.Due to increased number of vehicles as well as poor traffic management, road traffic has become one of the recent issues Sri Lanka facing. There is no system to help in traffic management and to decrease the road traffic in Sri Lanka.When it comes to traffic police, traffic control is personal biased and lack of experience may cause bigger traffic.When implementing a traffic light system statistical data are collected manually using human resources. False data and incorrectly entered data counts will definitely produce false results thus creating chaos in each junction. Violation of road traffic causes many road accidents. In Sri Lanka, traffic police monitor this issue manually and penalize the drivers. There are many instances where drivers violate rules but no evidence or presence of a traffic police set them free. The purpose of the built system is to ease the road traffic generated due Background and Related Works:-Uke and R. Thool [1] stated that vehicle counts, traffic classifications and speed estimation is done using C++ and OpenCV. Images from video streams are taken and background is extracted from them. Then the background is used to detect the moving traffic as well as classify the vehicle type. Based on the extracted subtraction objects which are not traffic are also detected and added into the counts thus creating false results in some instances.
Shukla and M. Saini [2] stated that in every vehicle detection system there are two stages. Hypothesis generation and verification. Sensing vehicle ahead before creating make it more sensible. Then formulating a dynamic traffic system helps to ease accidents and save time. There are few vehicle tracking approaches. One is region based tracking method. In this method the moving objects are tracked and those are taken for track the vehicles. These regions or area are divided using the subtracting process between the input image and background image which were stored before. For this model images taken from a stable camera was used. Contour tracking methods uses the boundary of the vehicle for detection. Its efficient is much greater than the previous method. 3D model based tracking methods uses 3D geometric shape of vehicles. Feature based tracking method, colour and pattern based tracking method are another two methods used for vehicle tracking.
Sharma et al. [3] proposed various image processing algorithms to detect vehicles. Their algorithm includes five steps in recognizing an object. Initial step would be to input an image then pre-process it, use differential morphology profile then threshold and filter. Algorithm is applied on frames which consist of the still images of the traffic. Then in the pre-processing step the true colour image would be converted in to grey level image according to the luminance converter. Morphology is a nonlinear technique in images processing where it can be used to noise filtering, image segmentation, pattern recognition, shape detection and shape decomposition. A feature vector is created from a single images using differential morphological profile. Then at the threshold stage grey level image is converted in to binary image using an equation. Target image would be extracted using computed shape index at the filtering stage. Finally, the vehicle is detected. The performance of the algorithm then will be calculated using three measures such as true, false and negative rate.
Wang et al. [4] stated that when it comes to vehicle detection algorithm based on deep belief network that there are two sets of categories existing. The first set is about vision based vehicle detection and the second set is on deep learning for object recognition. Vision based vehicle detection approach would be to use vehicle appearance characteristics such as local symmetry, edge, and cast shadow to detect vehicles. Features like Gabor features, scaleinvariant feature transform (SIFT) features, speeded up robust features (SURF) are used for vehicle representations. For training vehicle detectors Support vector machines (SVM) and Adaboost are used.
Chien and L. Chen [5] stated that the canny edge detector is used for edge detection and localization in image processing. Edge detectors based on morphological gradient performs well in edge detection. But the edge localization is weak. It can be further improved with erosion operations. Changing the threshold values the user can generate different results. P. Niksaz [6] conveyed that the road traffic had become a major problem which country faces today because of the increase in number of vehicles. The increase in number of vehicles follow-on to the need of a smart system that could resourcefully handle traffic congestion based on the density of traffic. To estimates the size of traffic in highways by using image processing has been proposed and as a result a message is shown to inform the number of cars in highway and aims to prevent heavy traffic in highways. There are lots of methods that can be utilized for Gamma correction.
Nagaraj et al. [7]mentioned that traffic control system can be built by image processing technique like edge detection to discovery the traffic concentration, based on traffic density can control the traffic signal light. There are current traffic control systems like Microcontroller, Vehicle-Actuated Control, Manual Controlling, and Automatic Traffic Light. Image processing alongside with object detection to sense traffic jam. It involves several steps of image processing to make decision about traffic jam. Main steps are Image Analysis, Object detection, typed object count, Motion detection, and Result representation.

12
In "Video Image Processing to Create a Speed Sensor" [8] stated that current methods to monitoring congested freeways and had neither the skill nor the expert to set lasting marks on the road. To do this they had used an algorithm for speed extraction first applies a sequence of operators to single images to create a set of boosted images. Then use this set of boosted images to create a speed approximation algorithm.
Hadi [9] mentioned about the main form of transmission & storage for information which has been by paper documents. Several good solutions exist for document processing and analysis, this research will give an outline for processing, analysis and grouping of document images. Today information technology has proved that there is a want to pile, query, search and get large amount of electronic information resourcefully and correctly. So document image processing is very interesting field of research with the continuous development of interest and growing security requirements for the growth of the modern civilization.
Margritet al. [10] stated that the digital image processing will be directing on analysis of remotely recognised images. These images are symbolised in digital form. When showed as numbers, brightness can be visible to statistical controls that are not possible if an image is accessible only as a photograph.Digital image processing of satellite data can be mainlyclustered into three groups. Improvement is applied to image data to successfullyshow data for subsequent visual understanding. Information mining is built on digital classification and is used for making digital thematic map. M. Kumar [11] stated about a real-time vision system that has been created that inspectscolor videos on a highway. This system uses a mixture of color, edge, and gestureevidence to identify and track the road limits, lane patterns and other vehicles on the road. Cars are identified by similar templates that are chosen from the input data online and by detecting highway scene features and measuring how they relate to each other. Cars are also identified by temporal differencing and by followinggesturelimitations that are for vehicles. Experimental results prove robust, real-time car discovery and tracing over thousands of image frames. The data contains video obtained under tough visibility situations. The totalpurpose of the research is to build a clever, camera-assisted car that is bright to understand its environments automatically, and in real time. Traffic size, driver behavior, lighting, and road conditions are hard to forecast. Their systemexamines the whole highway. It sections the road apparent from the image using colorarrangement, and then identifies and tracks lane patterns, road limitations and vehicles.
Akram et al. [12] recognized that one of the important applications of video-based management systems is the transportation surveillance. Within many years the researches have examined in the Vision-Based Intelligent Transportation System (ITS) Transportation preparation and traffic engineering apps to getvaluable and accurate data. It attentionson vehicle detection, tracking, and classifying. The research team categorise the traffic monitoring systems built on detailed methods which used for evolving it.
Jain et al. [13] stated that articles in numerouspapers it appearsrathertough to have straightcontrast. The formation of noticing the state of traffic in critical areascan be used to prevent seriousblocking.That system supposes specially in night time using density estimation algorithm but they can't find a good solution for it and tells that most suitable for low congestions in night time.
Loureiro et al. [14] founded about that in most of research papers, there are some common problems that can't solve in accurate manner such as shadowsand vehicle occlusion. There are some technical problems such as the low quality of the stream available and sometimes the low frame rate. Although some algorithms can tolerate lower frame rates, but that is generally not true for low quality images. They also found some camera related issues such as the depth. Zoom level will also effect on the detection as well.
Atko et al. [15] and Harish et al. [16] mentioned, vehicle tracking, vehicle speed measurement, recognition of license plate of moving vehicles and lane detection can be found in different systems.To do vehicle number plate recognition car should move through the observational zone and recognition program locationalise the number plate and tracks it while car is in this zone. Symbol recognition module selects frame of the greatest quality and finds it as symbol combination.Vehicle tracking is also built on contour extraction.

Methodology:-
This project uses prototype development methodology because the end target is to satisfyend user's which will result in a lot of implementations of updated versions of the previous systems that were created. Prototype is built, tested, and then reworked as necessary until an acceptable system is finally achieved from which the complete system or product can now be developed. This model works best in situations where not all of the project requirements are recognized in detail ahead of time. Fig 1,shows the prototype methodology.

Fig. 1:-Prototype Methodology
Planning:-The final outcome was considered each and every time at the planning stage. There were many stepped involved in planning.
The structure and design of the user interface was one stage of planning. The best user experience delivery was considered even though the project's objective was to predict the traffic. The interface creation was planned to implement using C# and the integrated development environment was the visual studio.
The next step at the planning stage was the data gathering methods for the analysis phase. Then how to design the most crucial parts such as the optimal green time prediction algorithm and object detection were considered.

Analysis:-
The second stage of prototyping methodology is analysing. The main objective of the analysis phase is to understand the processing requirement of this system. In the analysis phase the project team continue with gathering requirements about the research and prioritizing the requirements in order to achieve them step by step.
Project team identified the prediction algorithm and image processing as the main requirements and other methods as sub requirements. Toanalyse the current states information were gathered in many forms.
One of the main form of information gathering was the interviews with the traffic police and the relevant parties in this field. Current issues when it comes to the traffic were thoroughly recognized and analysed through this method.
Literature review was also used as an information gathering method at the analysing phase. To gather the relevant videos, site visiting was also done. Through site visiting the absolute real scenario was able to recognize and based on that the system was built.
14 Design:-The third stage of prototyping methodology is designing. In this phase the basis of the user interface was designed with the sketch of the entire system.
Then the prediction algorithm with the statistical point was developed taking into many considerations such as the circulation of the traffic lights for each lane, minimizing the waiting time, minimizing the accumulated traffic when the lane is closed and maximizing the traffic reduction of each lanes etc.
MySQL database was used when creating the system's database. MySQL Workbench was used as the visual database platform.
The interfaces for the system was built using visual studio as the integrated development environment. The programming language to do the above was C#.
The main components of the system are the prediction algorithm and the moving object detection algorithm. Both the components were built using C++ and R. For the prediction algorithm statistical methodologies and time prediction functions were also used. As the library OpenCV was thoroughly used for this has many methods and functions in image and video processing area. Fig 2, shows the system architecture. In fig 2, the upper most side picture is where live traffic is recorded into a video format where at the implementation stage it could be CCTV footage. Those footages are then send to the system and moving objects (vehicles) are then detected and counted. The results are stored on the database for predictions.The data processor represents the prediction algorithm which produces the optimal green time for each lane based on the traffic. The output would be the above predicted time.

Implementation:-
According to the information gathered a prototype of the system was developed. Also implementation was done by according to the requirements which we gathered. Following steps were done in this phase.  Implementation of the database for the system.  Implementation of the prediction and objectdetection algorithms.

15
 Connecting the interface with the database.  Connecting the algorithms with the database.
Genetic algorithm is used in order to generate the optimal green time.This process involves several steps.First step is the process of deciding the inputs.Average number of cars are the inputs in this scenario.As the population size a number is selected between 5-20 (rule of thumb). Number of generations are the number of iterations which the process runs.Chromosome size represents the number of green times need to be optimized .   Fig 3:-shows the process of genetic algorithm.

Fig. 3:-Genetic Algorithm Process
In fig 3, the next step is the generation of initial set of chromosomes (some random numbers that are appropriate for green times.). If the objective is to optimize green times of a four-way intersection, then chromosome size is 4. If you decide to use population size of 10, then in order to generate the first set of chromosomes, generate 4*10=40 random numbers between 10 and 110 (which are the maximum and minimum green times we initially designed) and arrange it as 10*4 matrix (10 population members with chromosome size 4). When objective function is minimized, the fitness will be maximized. Now using each of the 10 chromosomes in the population, fitness is calculated. Then set it aside and carry it into the next generation.
Next step is selecting the chromosome that has the highest fitness. After that the crossover phase begins. This is where new combinations are created from green times which will eventually become the best predictions. Then at the mutation process small changes to the created individual green times are added. Then the best solution will be selected at the end of the above processes.
16 Fig 4, shows the sample of green time prediction algorithm used in the system to calculate the optimal green time.

Fig. 4:-Green Time Prediction Algorithm Sample
In fig 4, as showed above the code represents the sample of the prediction algorithm which the system uses to predict the optimal green time. The C# code accesses the prediction algorithm written in R language through the Rengine function. The car counts retrieved from the object detection algorithm is passed as the parameters to the avgCars[] array, then the optimal time is calculated to minimize the traffic.
Object detection is accomplished by using C++ as the basic language and OpenCV as the image processing library. First the video file will be read and a line is created in order to detect the cars. Then each moving object is detected and whenever the object passes the above mentioned line car count for that video frame is incremented. This count is sent to the database where finally it will be used to predict the optimal green times.

Testing:-
The project team uses Unit testing method & Integration testing. Each member will be assigned separate sessions of testing. Generated results will be then checked for accuracy. In unit testing the testing is subdivided into the components which the system offers. Image processing, accuracy and working functions of prediction algorithms and database connectivity of each component are separately tested before integration.After the integration of each and every component the system is then tested as a whole to see whether the system generates the accurate results. Finally, stress testing is implemented to figure out the true capacity of the system and to detect bugs.

Results and Discussions:-
The accuracy of the prediction algorithm is depending on several values. One is the accuracy of the car counts retrieved by the object detection algorithm. Next is how the prediction algorithm is built to generate the optimal green times. Fig 5, shows the results of the prediction algorithm generated when the car counts are entered as parametersretrieved from the system's database.

Fig. 5:-Green Time Prediction Results
In fig 5, to generate the optimal green times the object value should be minimized. Until an optimal solution is selected the object value will be calculated up to the predefined iterations. The accuracy of the prediction algorithm 17 various when the maximum and minimum green times are defined. Only values between those values can be taken as answers. If there should be a green time that should be out of the range that correct value would not be taken as the green time. This was taken in order to make the system more realistic rather than trying to archive highest accuracy rate. So the accuracy rate varies from 60% to 70% percent.To check the accuracy of the system assigned green times for a particular junction is used. Based on the number of cars passed and accumulated due to the times allocated to each lane we were able to match the predicted green time versus the green times that particular junction already has. Based on the objective function to minimise the traffic each of the green times needed to be changed from the original value. This value is way off from the original green times assigned but are close to our predicted times. This method was able to calculate the system's accuracy level. Fig 6, shows the detection of objects, in our instance the vehicles on the road. These are then counted and used for predict the optimal green times.

Fig. 6:-Moving Object Detection and Counting
The other feature of the system is to detect the violations. This function is also obtained by the object detection methodology. Same as detecting the vehicles, the system recognises the road lines and whenever the moving object passes the line the object is captured thus this is sent to the database as road violations.

Conclusion:-
This paper describes the process of object detection and creation of prediction algorithm which provides the optimal time that can be used for a traffic light system. There are several limitations faced throughout this system. Moving objects detection accuracy depends on the quality of the footage thus bad weather conditions create difficulties in detecting and capturing the vehicles. The memory required to process a quality image depends on the memory and the performance of the machine we are using. It is highly recommended to use a super computer or computer with high performance capabilities in order to implement and run the system without crashing or lagging off. The camera should be focused while able to detect more vehicles on the road and not taking other moving objects into the frame in order to maximize the accuracy of the system.
As future implements a feature like remote control can be added to the system.This will enable the authorized user to control the traffic light system from a remote distance based on the incidents occurred at each junction. Data mining component can be added later on when more and more data gathered through the system. This enables the user to identify traffic patterns and later use the information for other purposes.