trriibbhhu uv vaann tunniiveerrssiityy …...figure 9.2 simulation of serial communication circuit...

82
TRIBHUVAN UNIVERSITY INSTITUTE OF ENGINEERING PULCHOWK CAMPUS A FINAL YEAR PROJECT REPORT ON AUTOMATIC TRAFFIC CONTROL SYSTEM USING DIGITAL IMAGE PROCESSING [EG777EX] By: Bikalpa Khatiwada (Roll No. 065/BEX/409) Hem Kanta Regmi (Roll No. 065/BEX/415) Janak Kumar Lal (Roll No. 065/BEX/416) Narayan Thapa (Roll No. 065/BEX/420) A PROJECT SUBMITTED TO THE DEPARTMENT OF ELECTRONICS AND COMPUTER ENGINEERING IN PARTIAL FULFILLMENT OF THE REQUIREMENT FOR THE BACHELOR‟S DEGREE IN ELECTRONICS AND COMMUNICATION ENGINEERING DEPARTMENT OF ELECTRONICS AND COMPUTER ENGINEERING LALITPUR, NEPAL October, 2012

Upload: others

Post on 13-Aug-2020

2 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: TRRIIBBHHU UV VAANN TUNNIIVEERRSSIITYY …...Figure 9.2 Simulation of Serial Communication Circuit in Proteus..... 50 Figure 9.3 A Frame Showing the Road Traffic ..... 51 Figure 9.4

TTRRIIBBHHUUVVAANN UUNNIIVVEERRSSIITTYY

IINNSSTTIITTUUTTEE OOFF EENNGGIINNEEEERRIINNGG

PPUULLCCHHOOWWKK CCAAMMPPUUSS

A

FINAL YEAR PROJECT REPORT

ON

AUTOMATIC TRAFFIC CONTROL SYSTEM USING DIGITAL IMAGE

PROCESSING

[EG777EX]

By:

Bikalpa Khatiwada (Roll No. 065/BEX/409)

Hem Kanta Regmi (Roll No. 065/BEX/415)

Janak Kumar Lal (Roll No. 065/BEX/416)

Narayan Thapa (Roll No. 065/BEX/420)

A PROJECT SUBMITTED TO THE DEPARTMENT OF ELECTRONICS AND

COMPUTER ENGINEERING IN PARTIAL FULFILLMENT OF THE

REQUIREMENT FOR THE BACHELOR‟S DEGREE IN

ELECTRONICS AND COMMUNICATION ENGINEERING

DEPARTMENT OF ELECTRONICS AND COMPUTER ENGINEERING

LALITPUR, NEPAL

October, 2012

Page 2: TRRIIBBHHU UV VAANN TUNNIIVEERRSSIITYY …...Figure 9.2 Simulation of Serial Communication Circuit in Proteus..... 50 Figure 9.3 A Frame Showing the Road Traffic ..... 51 Figure 9.4

ii

COPYRIGHT

The author has agreed that the Library, Department of Electronics and Computer

Engineering, Pulchowk Campus, Institute of Engineering may make this report freely

available for inspection. Moreover, the author has agreed that permission for extensive

copying of this project report for scholarly purpose may be granted by the supervisors who

supervised the project work recorded herein or, in their absence, by the Head of the

Department wherein the project report was done. It is understood that the recognition will

be given to the author of this report and to the Department of Electronics and Computer

Engineering, Pulchowk Campus, Institute of Engineering in any use of the material of this

project report. Copying or publication or the other use of this report for financial gain

without approval of to the Department of Electronics and Computer Engineering,

Pulchowk Campus, Institute of Engineering and author‟s written permission is prohibited.

Request for permission to copy or to make any other use of the material in this report in

whole or in part should be addressed to:

Head of Department

Department of Electronics and Computer Engineering

Pulchowk Campus, Institute of Engineering

Pulchowk, Lalitpur

Nepal

Page 3: TRRIIBBHHU UV VAANN TUNNIIVEERRSSIITYY …...Figure 9.2 Simulation of Serial Communication Circuit in Proteus..... 50 Figure 9.3 A Frame Showing the Road Traffic ..... 51 Figure 9.4

iii

ACKNOWLEDGEMENT

First of all, we would like to express our deep sense of gratitude to our project supervisor,

Dr. Surendra Shrestha, Associate Professor, Department of Electronics and

Computer Engineering, Pulchowk Campus, for providing a lot of inspiration and

intellectual guidance while being very encouraging and supportive.

We are highly indebted to the Department of Electronics and Computer Engineering,

Pulchowk Campus for providing this opportunity of collaborative undertaking which has

helped us develop a major project of our own that greatly enhances our knowledge and

provides a new experience of team-work, quite important for future career.

We would like to express our sincere gratitude to lecturer Dr. Sanjeeb Prasad Panday for

giving us enough time to provide us necessary guidance on image processing despite his

busy schedule.

We would like to express our sincere gratitude to the Robotics Club, Pulchowk Campus

and its members for providing us their invaluable assistance throughout the development

of the hardware part of this project.

We would like to thank all the teachers, friends and seniors for providing valuable

suggestions regarding the project.

Bikalpa Khatiwada ([email protected])

Hem Kanta Regmi ([email protected])

Janak Kumar Lal ([email protected])

Narayan Thapa ([email protected])

Page 4: TRRIIBBHHU UV VAANN TUNNIIVEERRSSIITYY …...Figure 9.2 Simulation of Serial Communication Circuit in Proteus..... 50 Figure 9.3 A Frame Showing the Road Traffic ..... 51 Figure 9.4

iv

ABSTRACT

Traffic lights at most road intersections operate on a fixed timing schedule that leads to

suboptimal traffic management, with unnecessary delays and thus lead to higher fuel

consumption and higher emissions. In this project, a system to detect vehicles and thus

determine their density in each street (or lane), based on digital image-processing

techniques has been developed. The project is, technically, divided into two parts – the

software part and the hardware part. The software part deals with processing of the images

of the vehicle traffic to generate the control decisions. The images used for processing can

be taken by pre-installed traffic surveillance cameras that are fixed at the top of the

existing traffic lights or fixed somewhere close to them. The hardware part deals with

controlling the traffic lights using an interface module on the basis of control decisions

provided by the software part. Although the system developed in this project cannot be

taken as an alternative, it can still be an option to facilitate the existing manual traffic

management system of Nepal.

Keywords: Traffic management, Traffic lights, Digital image processing, Vehicle density

detection

Page 5: TRRIIBBHHU UV VAANN TUNNIIVEERRSSIITYY …...Figure 9.2 Simulation of Serial Communication Circuit in Proteus..... 50 Figure 9.3 A Frame Showing the Road Traffic ..... 51 Figure 9.4

v

TABLE OF CONTENTS

COPYRIGHT......................................................................................................................... ii

ACKNOWLEDGEMENT .................................................................................................... iii

ABSTRACT.......................................................................................................................... iv

TABLE OF CONTENTS....................................................................................................... v

LIST OF FIGURES .............................................................................................................. ix

LIST OF TABLES ................................................................................................................. x

LIST OF ACRONYMS ........................................................................................................ xi

1. INTRODUCTION .......................................................................................................... 1

1.1. Background ............................................................................................................. 1

1.2. Objectives ................................................................................................................ 2

1.3. Traffic System Overview ........................................................................................ 3

1.3.1. Traffic Management System ............................................................................ 3

1.3.2. Traffic Junction Structure ................................................................................ 4

1.3.3. Traffic Light System ........................................................................................ 6

2. LITERATURE REVIEW ............................................................................................... 8

3. BACKGROUND THEORY ........................................................................................... 9

3.1. Traffic Engineering ................................................................................................. 9

3.1.1. General Principles of Signal Design .............................................................. 11

3.1.2. General Design Data for Traffic Intersection System ................................... 12

3.1.3. Trial Method of Cycle Design ....................................................................... 12

3.2. Digital Image Processing ...................................................................................... 13

3.2.1. Image Acquisition .......................................................................................... 13

3.2.2. Image Enhancement ....................................................................................... 14

3.2.3. Morphological Processing ............................................................................. 17

3.2.4. Segmentation ................................................................................................. 18

Page 6: TRRIIBBHHU UV VAANN TUNNIIVEERRSSIITYY …...Figure 9.2 Simulation of Serial Communication Circuit in Proteus..... 50 Figure 9.3 A Frame Showing the Road Traffic ..... 51 Figure 9.4

vi

3.3. Embedded System ................................................................................................. 19

3.3.1. Microcontroller .............................................................................................. 21

4. SYSTEM DEVELOPMENT ........................................................................................ 22

4.1. Preliminary investigation phase ............................................................................ 22

4.1.1. Problem in Existing System ........................................................................... 22

4.1.2. Application and Scope of Project .................................................................. 22

4.2. Problem Analysis Phase ........................................................................................ 23

4.2.1. Problem Domain ............................................................................................ 23

5. METHODOLOGY ....................................................................................................... 24

5.1. Traffic Detection ................................................................................................... 24

5.1.1. Manual Detection ........................................................................................... 24

5.1.2. Automatic Detection ...................................................................................... 24

5.2. Functional Block Diagram of the System ............................................................. 25

5.3. Image Processing Algorithms ............................................................................... 27

5.3.1. Image Acquisition .......................................................................................... 27

5.3.2. Image Enhancement ....................................................................................... 28

5.3.3. Background Subtraction ................................................................................ 29

5.3.4. Processing Upper Half of the Image .............................................................. 32

5.3.5. Processing Lower Half of the Image ............................................................. 34

6. HARDWARE IMPLEMENTATION .......................................................................... 36

6.1. Control Interface ................................................................................................... 36

6.1.1. Specification of Control Interface.................................................................. 36

6.2. Communication with PC ....................................................................................... 37

6.3. Current Amplifier .................................................................................................. 38

6.4. Traffic Lights Circuit ............................................................................................ 39

6.5. Tools Used for Simulation .................................................................................... 40

6.5.1. Proteus VSM .................................................................................................. 40

Page 7: TRRIIBBHHU UV VAANN TUNNIIVEERRSSIITYY …...Figure 9.2 Simulation of Serial Communication Circuit in Proteus..... 50 Figure 9.3 A Frame Showing the Road Traffic ..... 51 Figure 9.4

vii

6.5.2. Livewire ......................................................................................................... 41

6.6. Tools used for Circuit Design ............................................................................... 41

6.6.1. PCB Wizard ................................................................................................... 41

6.6.2. KiCAD ........................................................................................................... 41

6.7. Tools used for Microcontroller Programming ...................................................... 42

6.7.1. MPLAB .......................................................................................................... 42

7. SOFTWARE IMPLEMENTATION AND SIMULATION ........................................ 43

7.1. Programming Language and Tools ....................................................................... 43

7.2. Simulation Software/GUI...................................................................................... 43

8. PROBLEM FACED AND SOLUTIONS .................................................................... 46

8.1. Some Solved Problems ......................................................................................... 46

8.1.1. Software ......................................................................................................... 46

8.1.2. Hardware ........................................................................................................ 46

8.2. Some Unsolved Problems ..................................................................................... 47

8.2.1. Software ......................................................................................................... 47

9. RESULT AND ANALYSIS......................................................................................... 48

9.1. Experimental Setup ............................................................................................... 48

9.2. Hardware Testing .................................................................................................. 48

9.2.1. Basic Circuit Testing ..................................................................................... 48

9.2.2. Testing the Fixed Time System ..................................................................... 48

9.2.3. Testing the Traffic Light Circuit .................................................................... 49

9.2.4. Connecting the Control Interface and Traffic Light Circuit .......................... 49

9.2.5. Connecting Control Interface and PC ............................................................ 50

9.2.6. Connecting All Three Units and Testing ....................................................... 50

9.3. Software Testing ................................................................................................... 51

10. COST ANALYSIS OF THE PROJECT ................................................................... 53

11. LIMITATIONS AND FUTURE ENHANCEMENTS ............................................. 55

Page 8: TRRIIBBHHU UV VAANN TUNNIIVEERRSSIITYY …...Figure 9.2 Simulation of Serial Communication Circuit in Proteus..... 50 Figure 9.3 A Frame Showing the Road Traffic ..... 51 Figure 9.4

viii

11.1. Limitations ............................................................................................................ 55

11.2. Future Enhancements ............................................................................................ 55

12. CONCLUSION ......................................................................................................... 57

13. REFERENCES ......................................................................................................... 58

APPENDIX .......................................................................................................................... 60

Appendix A ...................................................................................................................... 60

Appendix B ...................................................................................................................... 61

Appendix C ...................................................................................................................... 62

Appendix D ...................................................................................................................... 64

Appendix E ...................................................................................................................... 65

Appendix F ....................................................................................................................... 67

Appendix F ....................................................................................................................... 68

Appendix G ...................................................................................................................... 69

Page 9: TRRIIBBHHU UV VAANN TUNNIIVEERRSSIITYY …...Figure 9.2 Simulation of Serial Communication Circuit in Proteus..... 50 Figure 9.3 A Frame Showing the Road Traffic ..... 51 Figure 9.4

ix

LIST OF FIGURES

Figure 1.1 Manual Traffic Management at Thapathali .......................................................... 4

Figure 1.2 Structure of Left-Handed Traffic Junction ........................................................... 5

Figure 1.3 Structure of Right-Handed Traffic Junction ......................................................... 5

Figure 1.4 Basic Structure of Traffic Light ........................................................................... 7

Figure 3.1 Block Diagram of DIP with Respect to this project ........................................... 13

Figure 5.1 Functional Block Diagram of Automatic Traffic Control System ..................... 25

Figure 5.2 DIP Algorithms Used in System Development .................................................. 28

Figure 5.3 Conventional Background Subtraction Procedure ............................................. 30

Figure 5.4 Original Image .................................................................................................... 31

Figure 5.5 Image With Only Objects of Interest ................................................................. 31

Figure 5.6 Upper Half Portion ............................................................................................ 32

Figure 5.7 Lower Half Portion ............................................................................................. 32

Figure 5.8 Thresholded Image ............................................................................................. 33

Figure 5.9 Clipping with Lines to get the Proper Count of Vehicle in the Image ............... 33

Figure 5.10 Dilated Image ................................................................................................... 34

Figure 5.11 Thresholded Image ........................................................................................... 34

Figure 6.1 Block Diagram of Hardware Implementation .................................................... 36

Figure 6.2 KiCAD Design of Control Interface .................................................................. 37

Figure 6.3 Circuit Diagram of a Darlington Pair using NPN Transistors............................ 38

Figure 6.4 LED Connections Using Darlington Pair ........................................................... 39

Figure 6.5 PCB Design of Traffic Light Circuit .................................................................. 40

Figure 7.1 Screenshot of the GUI ........................................................................................ 44

Figure 9.1 Simulation of Traffic Light Circuit in Proteus ................................................... 49

Figure 9.2 Simulation of Serial Communication Circuit in Proteus .................................... 50

Figure 9.3 A Frame Showing the Road Traffic ................................................................... 51

Figure 9.4 Section of GUI Showing the Number of Vehicles ............................................. 52

Page 10: TRRIIBBHHU UV VAANN TUNNIIVEERRSSIITYY …...Figure 9.2 Simulation of Serial Communication Circuit in Proteus..... 50 Figure 9.3 A Frame Showing the Road Traffic ..... 51 Figure 9.4

x

LIST OF TABLES

Table 9.1 Cost Analysis of the Project

Page 11: TRRIIBBHHU UV VAANN TUNNIIVEERRSSIITYY …...Figure 9.2 Simulation of Serial Communication Circuit in Proteus..... 50 Figure 9.3 A Frame Showing the Road Traffic ..... 51 Figure 9.4

xi

LIST OF ACRONYMS

2D Two Dimensional

3D Three Dimensional

BSD Berkeley Software Distribution

CAD Computer Aided Design

CC Closed Circuit

CCD Charge Coupled Device

CMOS Complementary Metal–Oxide–Semiconductor

CUDA Compute Unified Device Architecture

DIP Digital Image Processing

DU Decision Unit

GPU Graphical Processing Unit

GUI Graphical User Interface

HCI Human – Computer Interaction

IDE Integrated Development Environment

IPU Image Processing Unit

I/O Input/Output

LCD Liquid Crystal Display

LED Light Emitting Diode

MATLAB MATrix LABoratory

MPLAB MicroProcessor LABoratory

mA milli-Ampere

Page 12: TRRIIBBHHU UV VAANN TUNNIIVEERRSSIITYY …...Figure 9.2 Simulation of Serial Communication Circuit in Proteus..... 50 Figure 9.3 A Frame Showing the Road Traffic ..... 51 Figure 9.4

xii

OS Operating System

OTP One Time Programmable

PC Personal Computer

PCB Printed Circuit Board

PDA Personal Digital Assistant

RAM Random Access Memory

RFID Radio – Frequency Identification

ROM Read Only Memory

RTOS Real Time Operating System

SDK Software Development Kit

SFM Structure From Motion

SPICE Simulation Program for Integrated Circuits Emphasis

SQL Structured Query Language

SVN SubVersioN

TTL Transistor – Transistor Logic

USB Universal Serial Bus

VIP Very Important Person

VSM Virtual System Modelling

Page 13: TRRIIBBHHU UV VAANN TUNNIIVEERRSSIITYY …...Figure 9.2 Simulation of Serial Communication Circuit in Proteus..... 50 Figure 9.3 A Frame Showing the Road Traffic ..... 51 Figure 9.4

1

1. INTRODUCTION

1.1. Background

The increase in urban traffic brings with it the problem of frequent traffic jams at major

traffic junctions. This requires for an efficient traffic management system to be

implemented at such places. Commonly, special organized government body such as

Metropolitan Traffic Police Division (as in case of Nepal) is established to manage the

vehicle traffic of the streets. The traffic personnel are responsible to look after the traffic

conditions and take necessary steps to eliminate any sort of traffic congestions. A special

arrangement of traffic lights is installed at every junction to control the vehicle traffic of

every constituent street.

In metropolitan cities or urban areas of the developed nations where the number of vehicles

is proportional to the width of the streets, these traffic lights are so adjusted that they turn

on and off at certain intervals of time and allow the vehicles to move across the junction

after every certain time interval. Similar traffic light systems can also be found installed in

the traffic junctions of major cities of Nepal such as Kathmandu. Unlike the streets of

foreign countries, the width of the streets is not sufficient enough to serve the vehicle

traffic that presently exists in the city. Besides, the streets of Kathmandu remain

overcrowded by the vehicles especially during the day time on weekdays. Hence, the

traffic light system that switches the traffic lights at certain fixed intervals of time

regardless of the vehicle traffic on different streets is quite ineffective to manage the traffic

at the junction. Moreover, due to the unnecessary regular power cuts as well, the available

traffic lights also cannot be operated as and when needed and hence cannot be relied upon.

As a result, during such time periods of the daytime, a group of 6 to 10 traffic personnel

with 4 - 4 hours shift in-between is mobilized at each traffic junction and they are assigned

the responsibility to eliminate the unnecessary problem of traffic jams.

Furthermore, there is no special arrangement of traffic lights to enforce traffic rules and

regulations outside Kathmandu valley. Hence, the traffic personnel need to be fully

dedicated and responsible to enforce traffic rules and regulations so as to manage vehicle

traffic in all those places.

Page 14: TRRIIBBHHU UV VAANN TUNNIIVEERRSSIITYY …...Figure 9.2 Simulation of Serial Communication Circuit in Proteus..... 50 Figure 9.3 A Frame Showing the Road Traffic ..... 51 Figure 9.4

2

Depending upon the vehicle traffic, the traffic personnel allow the vehicles from different

streets to move across junction (to another street) for different time intervals. Thus, they

attempt to avoid any instantaneous traffic jam(s) at the junction.

The manual steps taken in favour of traffic management as explained above can also be

automated. Especially in a country like Nepal, where the vehicle traffic equally contributes

to air pollution, there is a great need of automated traffic control system so that the traffic

personnel can avoid themselves from the adverse consequences of air pollution.

Traffic signals generated solely by timer based circuit that operate according to the

predetermined timing sequence may not always be appropriate to manage the vehicle

traffic. Hence, when not manually operated, the traffic signals should be generated by real-

time processing of the vehicle traffic so that it can compensate for the varying traffic

density and better manage the traffic.

Automatic traffic management system can be achieved through one or the integration of

the following systems: wireless communications, computational technologies, floating

cellular data, sensing technologies, inductive loop detection, and video vehicle detection.

In this project, the automation of the traffic control system has been implemented on the

basis of the digital image processing. [1]

Digital image processing is associated with the various operations that are performed to

process the digital images for various purposes such as image enhancement, image

restoration and likewise. In context of this project, it has been extensively employed to

process the real-time images of the vehicles that constitute the road traffic and on the basis

of the density of the vehicles in the road, the appropriate traffic signals are generated.

1.2. Objectives

The main objective of this project is to build an automatic system that takes decision in

real time to control traffic lights using digital image processing. The system measures the

traffic queue length using image processing sensors and generates necessary control

signals. For this purpose, an integrated system of hardware for controlling the traffic lights

and software for image processing has been designed that accomplishes the task of

Page 15: TRRIIBBHHU UV VAANN TUNNIIVEERRSSIITYY …...Figure 9.2 Simulation of Serial Communication Circuit in Proteus..... 50 Figure 9.3 A Frame Showing the Road Traffic ..... 51 Figure 9.4

3

automatic traffic management and overcomes the short comings of the existing traffic

management system. Apart from this, the software developed in this project also simulates

the traffic light control system and facilitates the surveillance of road traffic as well as

helps to monitor the functioning of the traffic lights from a single computer or laptop in

which the software has been installed.

1.3. Traffic System Overview

1.3.1. Traffic Management System

In general, the traffic management system comprises the traffic lights fixed permanently at

appropriate places at the traffic junction and a control system designed to operate them,

which may be kept in the vicinity of the traffic lights or somewhere remotely located. The

vehicles should move (or stop) in accordance with the traffic signal produced by the traffic

light(s). Although traffic lights have been installed at various traffic junctions throughout

the urban areas of Kathmandu valley, they do not yield optimum outputs for effective

traffic management for various reasons. As a result, the task of traffic management is

assigned to the traffic personnel mobilized by the Metropolitan Traffic Police Division.

Hence, in one way or another, the traffic management system in Nepal is manual as shown

in Figure 1.1.

Apart from this, the traffic system of a country is either right handed or left-handed.

Despite some exceptional cases such as the segment of road that lies between Rani Pokhari

and Ratna Park which is right-handed, Nepal has left-handed traffic system i.e. the traffic

moves forward along the left side of the road.

In Nepal, no separate lanes have been designed for the four wheelers and two wheelers.

Both four and two wheelers share the same lane such that no distinct rules to overtake

vehicles have been specified by the Metropolitan Traffic Police Division as well.

The pedestrians are allowed to cross the road using the zebra-crossing or the sky bridge.

Unlike the sky bridge, which is accessible to the pedestrians at all times as it is built above

the roads, the zebra-crossings are often placed at the traffic junctions and hence, can be

used only when the vehicles along the lane which has the zebra-crossing are stopped as per

the traffic signals.

Page 16: TRRIIBBHHU UV VAANN TUNNIIVEERRSSIITYY …...Figure 9.2 Simulation of Serial Communication Circuit in Proteus..... 50 Figure 9.3 A Frame Showing the Road Traffic ..... 51 Figure 9.4

4

Figure 1.1 Manual Traffic Management at Thapathali

1.3.2. Traffic Junction Structure

A general structure of the traffic junction is shown in Figures 1.2 and 1.3. The Figures 1.2

and 1.3 correspond to the left-handed and right-handed traffic systems respectively. In the

left-handed traffic system, the vehicles are always allowed to make left turning.

Page 17: TRRIIBBHHU UV VAANN TUNNIIVEERRSSIITYY …...Figure 9.2 Simulation of Serial Communication Circuit in Proteus..... 50 Figure 9.3 A Frame Showing the Road Traffic ..... 51 Figure 9.4

5

Figure 1.2 Structure of Left-Handed Traffic Junction

The arrows show the directions along which the vehicles from each street are allowed to

move across the junction i.e. the vehicles are free to move from West to North, East to

South, South to West and North to East.

Normally, the movement of vehicles or traffic across the junction is done in the following

order [1]:

STEP 1: The traffic is allowed to move in W – S and W – E direction.

STEP 2: The traffic is allowed to move in N – S and N – W direction.

STEP 3: The traffic is allowed to move in E – W and E – S direction.

STEP 4: The traffic is allowed to move in S – N and S – E direction.

Figure 1.3 Structure of Right-Handed Traffic Junction

Page 18: TRRIIBBHHU UV VAANN TUNNIIVEERRSSIITYY …...Figure 9.2 Simulation of Serial Communication Circuit in Proteus..... 50 Figure 9.3 A Frame Showing the Road Traffic ..... 51 Figure 9.4

6

All the movements of vehicles mentioned above are given equal time in case of normal

traffic conditions. Here the normal traffic means the one in which traffic density is

relatively equal in all the streets.

If the density in one direction is relatively more in comparison to others then the time for

the movement of the vehicles along that direction is increased and if the density of traffic is

relatively less than others and is also less than that during normal condition then the time

for movement of vehicles along that direction is decreased. In such cases, the traffic

management is not bound by the rule to follow above steps.

1.3.3. Traffic Light System

Traffic signals consist of an arrangement of different coloured lights which are collectively

called traffic lights. The traffic lights are signaling devices positioned at road intersections,

pedestrian crossings and other locations to control competing flows of traffic. The simple

and/or basic arrangement of traffic lights has been indicated by the alphabets A, B, C and

D in Figures 1.2 and 1.3. Depending upon the intensity of vehicles arriving at the junction,

the number and positions of the traffic light arrangement may vary.

The traffic light system usually consists of three types of traffic lights each representing

three different colours. They are as follows:

I) Red

II) Amber

III) Green

I) Red

The red light is used to indicate the vehicles to stop at traffic junction. The main reason to

choose red light for this purpose was that the colour red generally symbolizes danger or

warning. Apart from this, the red light can be distinguished very correctly from a great

distance and even under poor visibility conditions such as during fog.

Page 19: TRRIIBBHHU UV VAANN TUNNIIVEERRSSIITYY …...Figure 9.2 Simulation of Serial Communication Circuit in Proteus..... 50 Figure 9.3 A Frame Showing the Road Traffic ..... 51 Figure 9.4

7

II) Amber

The amber or yellow light is used to indicate that the red light is about to glow next at any

instant. The yellow colour is generally used as a warning or caution symbol. Besides, it

contrasts well with the colours green and red, and is highly visible without being too harsh

on the eyes of vehicle riders.

III) Green

The green light is used to indicate the vehicles to move across the junction if they were

previously stopped.

In short green light means „go‟ and red light means „stop‟. The basic structure of a traffic

light is shown in Figure 1.4.

- R represents Red light.

- Y represents Yellow or Amber light.

- G represents Green light.

Figure 1.4 Basic Structure of Traffic Light

R

Y

G

Page 20: TRRIIBBHHU UV VAANN TUNNIIVEERRSSIITYY …...Figure 9.2 Simulation of Serial Communication Circuit in Proteus..... 50 Figure 9.3 A Frame Showing the Road Traffic ..... 51 Figure 9.4

8

2. LITERATURE REVIEW

The projects addressing similar problems have been done at both national and international

levels. Those projects also perform the automatic control of traffic on the basis of digital

image processing. The projects that were done at national level include “Model Based

Automatic Traffic Control System” by Indu Bhandari and Kamal K.C. and “Traffic

Control and Surveillance System” by Niraja Shakya, Sujana Gurung and Vandana Dhakal.

The project entitled “Model Based Automatic Traffic Control System” employed the DIP

algorithms such as background subtraction and basic global thresholding to accomplish the

task of automatic vehicle detection. This system produced satisfactory results on the

prototype of the traffic intersection that used miniature toy vehicles on the prototype to

simulate the traffic and the traffic density was determined after analyzing the video taken

by the web-camera.

The project entitled “Traffic Control and Surveillance System” implemented the DIP

algorithms such as edge detection and background subtraction to detect vehicles. This

system also consists of a buzzer system which is blown to indicate the pedestrians that it is

safe to cross the road. In both the projects mentioned above, MATLAB was used as the

tool for DIP.

In international level, many research works have been carried out for the automatic

detection of vehicles using DIP algorithms. Some of such works include “Image

Processing Based Intelligent Traffic Controller” done by Vikramaditya Dangi, Amol

Parab, Kshitij Pawar and S.S Rathod, and “Image Processing Algorithms for Detecting and

Counting Vehicles Waiting at a Traffic Light” done by Ernesto de la Rocha, Rafael

Palacios. Basically, the research work of Ernesto de la Rocha, Rafael Palacios has provided

a great help and guidance to develop the concept about the necessary image processing

algorithms that could be implemented for the automatic detection of vehicles using DIP

approach.

Page 21: TRRIIBBHHU UV VAANN TUNNIIVEERRSSIITYY …...Figure 9.2 Simulation of Serial Communication Circuit in Proteus..... 50 Figure 9.3 A Frame Showing the Road Traffic ..... 51 Figure 9.4

9

3. BACKGROUND THEORY

3.1. Traffic Engineering

At large intersections and crossing, right-turning traffic has to come across several

collision points, and hence, there is possibility of accident. At small intersection, vehicle

traffic is controlled by traffic personnel alternately showing stop signs to the incoming

traffic on roads. Traffic signals are such control device which can alternately direct the

traffic to stop and proceed at level intersections. The main requirement of traffic signals is

to draw attention, provide meaningful time to respond and have minimum waste of time.

[2]

There are many advantages and disadvantages of traffic signals. Some of the advantages

can be listed as follows:

- Movement of traffic on level intersection is more orderly and safe.

- Traffic handling capacity of the intersection is increased.

- Right angled collision points are reduced thus reducing the accident possibilities.

- Traffic signals when subjected to automatic control prove to be more economical

than manually operated signals.

- Due to stoppage at intersections, compact streams of traffic are formed which

improve flow of traffic.

- If signal system at several intersections is properly co-ordinated, reasonably good

speed of traffic on the main road can be maintained.

- Pedestrians can cross the roads safely at the signalised intersection.

- The signals allow crossing of the heavy traffic flow with safety.

- Signals provide chance to crossing traffic of minor road to cross the path of

continuous flow stream at reasonable intervals of time.

Similarly, the disadvantages of having traffic signals can be listed as follows:

- In case of automatic control, failure of power may cause lot of confusion.

- Possibilities of rear-end collision are increased.

- Incorrectly designed and located signals may induce traffic violations.

Page 22: TRRIIBBHHU UV VAANN TUNNIIVEERRSSIITYY …...Figure 9.2 Simulation of Serial Communication Circuit in Proteus..... 50 Figure 9.3 A Frame Showing the Road Traffic ..... 51 Figure 9.4

10

- In case of automatic signals, operated at fixed interval, a vehicle in urgency may

have to wait at intersection even if there is no traffic on crossing road, only because

signal is showing red light to him.

The capacity of a traffic intersection, operated by signals is dependent on roadway width,

number of lanes, geometric standards, operational and control factors.

With the advancement in the field of transportation and increase in the use of vehicles, the

need for advanced and improved traffic management system became vital. This led to the

invention of various types of traffic control signals. The types of traffic control signals are

as follows:

I) Manually operated light signals.

II) Fixed-time automatic light signals.

III) Traffic actuated light signals.

I) Manually Operated Light Signals

Light signal posts are fixed at the left hand side of the approaching vehicles at all the

entrance points to the intersection. These posts are provided with red, yellow amber and

green lights arrangements. These lights are so interconnected that they can be switched off

or switched on from a single common point.

II) Fixed-time Automatic Signals

These signals are also known as predetermined timing sequence traffic signals. They are

set to repeat at regular intervals at a specified sequence of signal indications. The timing of

each phase of cycle is determined based on traffic studies. They are operated automatically

with the help of electronic control. They have advantage of having less first cost, and with

a series of interconnected signals, vehicle can move through a series of intersections with

minimum of stops and delays. They may prove dangerous at occasions when due to some

defect vehicle may stop at the intersections. Similarly, one more drawback is that traffic on

the roads may have to wait because of red light and there may not be any traffic crossing

the road.

Page 23: TRRIIBBHHU UV VAANN TUNNIIVEERRSSIITYY …...Figure 9.2 Simulation of Serial Communication Circuit in Proteus..... 50 Figure 9.3 A Frame Showing the Road Traffic ..... 51 Figure 9.4

11

III) Traffic Actuated Signals

In this type of signals, timings of the phase and cycle can be changed according to the

traffic needs. In fully traffic-actuated signals detectors are located on each approach which

assigns the right way to various traffic movements on the basis of demand. On demand

from the cross street, the signal indication will changes at once if the main road had no

traffic.

3.1.1. General Principles of Signal Design

Certain standards or rules need to be followed so as to design the traffic signalling

mechanism or apparatus. This is mainly done so as to bring uniformity in the similar

approach implemented throughout a region or a country. Some of such principles of signal

design are as follows:

1) Red phase (explained in Appendix A) R1 i.e. the time duration for which the red

light is illuminated, of a signal is the sum of green and amber phases.

2) Near the end of the red phases, amber lights are switched on along with the red

lights to indicate „get set and go‟. This phase is known as „red amber‟ or „initial

amber‟ phase. The vehicles are not supposed to cross the stop line, which may

usually be the zebra crossing, during red amber phase.

3) Clearance amber or clearance time is provided just after green phase before the red

phase to fulfil following two requirements:

i. Stopping time for the approaching vehicle to stop at the stop line after the

signal changes from green to amber and not to cross the line by the time the

signal changes to red phase.

ii. Clearance time for the vehicle which is approaching the stop line at

permissible speed while the signal changes from green to amber. Usually

interval of 2 to 4 seconds is fixed for the amber phase.

4) Green time is decided based on the approach volume or the quantity/number of

vehicles arriving at the traffic junction during peak hour and the sufficient time

required by the queued vehicles to clear off in most of the cycles.

Page 24: TRRIIBBHHU UV VAANN TUNNIIVEERRSSIITYY …...Figure 9.2 Simulation of Serial Communication Circuit in Proteus..... 50 Figure 9.3 A Frame Showing the Road Traffic ..... 51 Figure 9.4

12

3.1.2. General Design Data for Traffic Intersection System

1. Cycle length (explained in Appendix A) for two phase signal is mostly 40 to 60

seconds.

2. Timing of yellow or amber colour varies from 3 to 5 seconds.

3. Timing for green light may be nearly 20 seconds.

4. Timing for red light is slightly less than green light.

5. Clearance of pedestrian time is calculated on the basis of average walking speed

of the pedestrians, which is usually defined to be 1.2 metres per second.

3.1.3. Trial Method of Cycle Design

Let A and B be two roads intersecting at a point and it is required to design cycle length for

this intersection.

i. For 15 minutes take traffic counts on road A and B, simultaneously at the same

intersection.

ii. Let N1 and N2 be the traffic counts of 15 minutes for A and B roads respectively.

iii. Assume suitable trial cycle length of C seconds.

iv. Based on the assumed value of C, calculate the number of cycles in 15 minute

period as follows [2]:

(2.1)

v. Assume 2.5 seconds head-way time and calculate green light periods GA and GB for

roads A and B respectively as follows [2]:

(2.2)

(2.3)

vi. Assume yellow or amber periods of YA and YB for A and B roads.

Page 25: TRRIIBBHHU UV VAANN TUNNIIVEERRSSIITYY …...Figure 9.2 Simulation of Serial Communication Circuit in Proteus..... 50 Figure 9.3 A Frame Showing the Road Traffic ..... 51 Figure 9.4

13

vii. Calculate the time [2]:

(2.4)

viii. If the calculated cycle length C1 works out approximately equal to the assumed

cycle, C, the cycle length is accepted as design cycle. Otherwise trials are repeated.

3.2. Digital Image Processing

Digital image processing encompasses processes whose inputs and outputs are images and,

in addition, encompasses processes that extract attributes from images, up to and including

recognition of the individual objects. [3]

An image may be defined as two-dimensional function f(x, y), where x and y are spatial

(plane) coordinates, and the amplitude of f at any pair of coordinates (x, y) is called the

intensity or gray level of the image at that point. When x, y, and the amplitude values of f

are all finite, discrete quantities, we call the image a digital image. The field of digital

image processing refers to the processing of the digital images by means of digital

computer. A digital image is composed of a finite number of elements, each of which has a

particular location and value. These elements are referred to as picture elements or pixels.

[3]

Figure 3.1 Block Diagram of DIP with Respect to this project

3.2.1. Image Acquisition

Images are generated by the combination of an “illumination” source and the reflection or

absorption of energy from that source by the elements of the “scene” being imaged.

Image Acquisition

Image Enhancement

Morphological Processing

Segmentation

Page 26: TRRIIBBHHU UV VAANN TUNNIIVEERRSSIITYY …...Figure 9.2 Simulation of Serial Communication Circuit in Proteus..... 50 Figure 9.3 A Frame Showing the Road Traffic ..... 51 Figure 9.4

14

An image sensor is a device that converts an optical image into an electronic signal. It is

used mostly in digital cameras, camera modules and other imaging devices. Early analog

sensors were video camera tubes, most currently used are digital charge-coupled device

(CCD) or complementary metal–oxide–semiconductor (CMOS) active pixel sensors.

Most digital still cameras use either a CCD image sensor or a CMOS sensor. Both types of

sensor accomplish the same task of capturing light and converting it into electrical signals.

A CCD image sensor is an analog device. When light strikes the chip it is held as a small

electrical charge in each photo sensor. The charges are converted to voltage one pixel at a

time as they are read from the chip. Additional circuitry in the camera converts the voltage

into digital information.

A CMOS imaging chip is a type of active pixel sensor made using the CMOS

semiconductor process. Extra circuitry next to each photo sensor converts the light energy

to a voltage. Additional circuitry on the chip may be included to convert the voltage to

digital data.

A digital camera (or digicam) is a camera that takes video or still photographs by recording

images on an electronic image sensor. Most cameras sold today are digital and digital

cameras are incorporated into many devices ranging from PDAs and mobile phones (called

camera phones) to vehicles.

Digital and film cameras share an optical system, typically using a lens with a variable

diaphragm to focus light onto an image pickup device. The diaphragm and shutter admit

the correct amount of light to the imager, just as with film but the image pickup device is

electronic rather than chemical. However, unlike film cameras, digital cameras can display

images on a screen immediately after being recorded, and store and delete images from

memory. Many digital cameras can also record moving video with sound. Some digital

cameras can crop and stitch pictures as well as perform other elementary image editing.

3.2.2. Image Enhancement

Image enhancement comprises the algorithms that make necessary changes to the original

images so that they can be made more useful for further processing. It eliminates the noise

Page 27: TRRIIBBHHU UV VAANN TUNNIIVEERRSSIITYY …...Figure 9.2 Simulation of Serial Communication Circuit in Proteus..... 50 Figure 9.3 A Frame Showing the Road Traffic ..... 51 Figure 9.4

15

introduced in the images either during acquisition or during digitization. Apart from this, it

is used to make the lighting adjustments in the images that are taken under unfavourable

lighting conditions such as during gloomy day or in a poorly illuminated room. With

regards to this project, image enhancement has been implemented to eliminate the noise

using the median and low-pass Gaussian filter and adjust the shortcomings of lighting

conditions using the histogram equalization technique.

I) Median Filter

In median filtering, the neighbouring pixels are ranked according to brightness (intensity)

and the median value becomes the new value for the central pixel. Median filters can do an

excellent job of rejecting certain types of noise, in particular, “shot” or impulse noise also

called “salt and pepper” in which some individual pixels have extreme values. In the

median filtering operation, the pixel values in the neighbourhood window are ranked

according to intensity, and the middle value (the median) becomes the output value for the

pixel under evaluation.

There is no reduction in contrast across steps, since output values available consist only of

those present in the neighbourhood (no averages). Median filtering does not shift

boundaries, as can happen with conventional smoothing filters (a contrast dependent

problem). Since the median is less sensitive than the mean to extreme values (outliers),

those extreme values are more effectively removed. The median is, in a sense, a more

robust “average” than the mean, as it is not affected by outliers (extreme values). Since the

output pixel value is one of the neighbouring values, new “unrealistic” values are not

created near edges. Since edges are minimally degraded, median filters can be applied

repeatedly, if necessary.

II) Gaussian Filter

Edges and other sharp transitions (such as noise) in the gray levels of an image contribute

significantly to the high-frequency component of its Fourier transform. Hence, smoothing

is achieved in the frequency domain by attenuating a specified range of high-frequency

components in the transform of a given range.

Page 28: TRRIIBBHHU UV VAANN TUNNIIVEERRSSIITYY …...Figure 9.2 Simulation of Serial Communication Circuit in Proteus..... 50 Figure 9.3 A Frame Showing the Road Traffic ..... 51 Figure 9.4

16

Basic model of the filtering in the frequency domain is given by the following equation

[3]:

G(u, v) = H(u, v)F(u, v) (2.5)

F(u, v) is the Fourier transform of the image to be smoothed.

H(u, v) is the filter transfer function.

G(u, v) is output of the process.

Gaussian low-pass filter is one of the filters used to eliminate the edges and other sharp

transitions (such as noise) in the gray levels from an image.

The form of the Gaussian low-pass filtering in the 2-D is given by [3]:

( ) ( ) (2.6)

D(u, v) is the distance from the origin of the Fourier transform, which is assumed to be

shifted to the centre of the frequency rectangle.

III) Histogram Equalization

Histogram equalization is a method in image processing of contrast adjustment using the

image's histogram. This method usually increases the global contrast of many images,

especially when the usable data of the image is represented by close contrast values.

Through this adjustment, the intensities can be better distributed on the histogram. This

allows for areas of lower local contrast to gain a higher contrast.

Histogram equalization accomplishes this by effectively spreading out the most frequent

intensity values. The method is useful in images with backgrounds and foregrounds that

are both bright or both dark.

Courtesy: “Histogram equalization” http://en.wikipedia.org/wiki/Histogram_equalization, 2012

Page 29: TRRIIBBHHU UV VAANN TUNNIIVEERRSSIITYY …...Figure 9.2 Simulation of Serial Communication Circuit in Proteus..... 50 Figure 9.3 A Frame Showing the Road Traffic ..... 51 Figure 9.4

17

3.2.3. Morphological Processing

The basic morphological transformations are called dilation and erosion, and they arise in a

wide variety of contexts such as removing noise, isolating individual elements, and joining

disparate elements in an image. Morphology can also be used to find intensity bumps or

holes in an image and to find image gradients. [4]

I) Dilation

Dilation is a morphological transformation of the image that causes bright regions within

an image to grow. [4]

Dilation is a convolution of some image (or region of an image), say A, with some kernel,

say B. The kernel, which can be any shape or size, has a single defined anchor point. Most

often, the kernel is a small solid square or disk with the anchor point at the center. The

kernel can be thought of as a template or mask, and its effect for dilation is that of a local

maximum operator. As the kernel B is scanned over the image, the maximal pixel value

overlapped by B is computed and the image pixel under the anchor point is replaced with

that maximal value. This causes bright regions within an image to grow. This growth is the

origin of the term “dilation operator”. [4]

II) Erosion

Erosion is the converse of dilation. The action of the erosion operator is equivalent to

computing a local minimum over the area of the kernel. Erosion generates a new image

from the original using the following algorithm: as the kernel B, similar to the one

mentioned above, is scanned over the image, the minimal pixel value overlapped by B is

computed and the image pixel under the anchor point is replaced with that minimal value.

[4] This causes the narrow connected regions in the image to diminish.

In general, whereas dilation expands region A, erosion reduces region A. Moreover,

dilation will tend to smooth concavities and erosion will tend to smooth away protrusions.

Page 30: TRRIIBBHHU UV VAANN TUNNIIVEERRSSIITYY …...Figure 9.2 Simulation of Serial Communication Circuit in Proteus..... 50 Figure 9.3 A Frame Showing the Road Traffic ..... 51 Figure 9.4

18

Of course, the exact result will depend on the kernel, but these statements are generally

true for the filled convex kernels typically used. [4]

3.2.4. Segmentation

Segmentation subdivides an image into its constituent regions or objects. The level to

which subdivision is carried depends on the problem being solved. That is, segmentation

should stop when the object of interest in an operation has been isolated. In this project, the

thresholding algorithms have been extensively used for the purpose of segmentation [3].

Thresholding

Consider an image, f(x, y), composed of light objects on a dark background, in such a way

that object and background pixels have gray levels grouped into two dominant modes. One

obvious way to extract the objects from the background is to select a threshold T that

separates these modes. Then any point (x, y) for which f(x, y)>T is called an object point;

otherwise, the point is called a background point. When T depends only on f(x, y) (that is,

only gray-level values) the threshold is called global. If T depends on both f(x, y) and

p(x,y), which is some local property of the point (x,y), the threshold is called local. If, in

addition, T depends on the spatial coordinates x and y, the threshold is called dynamic or

adaptive. [3]

I) Basic Global Thresholding

The simplest of all thresholding technique is to partition the image histogram by using a

single global threshold, T. Segmentation is then accomplished by scanning the image pixel

by pixel and labelling each pixel as object or background, depending upon whether the

gray level of that pixel is greater or less than the value of T. The success of this method

depends entirely on how well the histogram can be partitioned [3].

The following algorithm is used to obtain T:

1. Select an initial estimate of T.

Page 31: TRRIIBBHHU UV VAANN TUNNIIVEERRSSIITYY …...Figure 9.2 Simulation of Serial Communication Circuit in Proteus..... 50 Figure 9.3 A Frame Showing the Road Traffic ..... 51 Figure 9.4

19

2. Segment the image using T. This will produce two groups of pixels: G1 consisting

of all pixels with gray level values >T and G2 consisting of pixels with values ≤ T.

Compute the average gray level values μ1 and μ2 for the pixels in the regions G1 and

G2.

3. Compute the new threshold value [3] :

(2.7)

4. Repeat steps 2 through 4 until the difference in T in successive iterations is smaller

than a predefined parameter T0.

II) Adaptive Thresholding

Adaptive thresholding is used in case when a histogram cannot be partitioned effectively

by a single global threshold. An approach for handling such a situation is to divide the

original image into sub-images and then utilize a different threshold to segment each sub-

image. The image is subdivided into smaller sub-images, such that the illumination of each

sub-image is approximately uniform. Since the threshold used for each pixel depends on

the location of the pixel in terms of the sub-images, this type of thresholding is called

adaptive thresholding [3].

3.3. Embedded System

An embedded system is a computer system designed to perform one or a few dedicated

function often with real-time computing constraints. It is embedded as part of a complete

device often including hardware and mechanical parts. An embedded system can be

defined as “A system whose principal function is not computational, but which is

controlled by a computer embedded within it. The computer is likely to be a

microprocessor or microcontroller. The word embedded implies that it lies inside the

overall system, hidden from view, forming an integral part of greater whole.”

Physically, embedded systems can be found in wide range of electronic equipments

ranging from portable devices such as digital watches and MP3 players, to large stationary

Page 32: TRRIIBBHHU UV VAANN TUNNIIVEERRSSIITYY …...Figure 9.2 Simulation of Serial Communication Circuit in Proteus..... 50 Figure 9.3 A Frame Showing the Road Traffic ..... 51 Figure 9.4

20

installations like traffic lights, factory controllers, or the systems controlling nuclear power

plants. Complexity varies from low, with a single microcontroller chip, to very high with

multiple units, peripherals and networks mounted inside a large chassis or enclosure.

Courtesy: “Embedded system” http://en.wikipedia.org/wiki/Embedded_system, 2012

An embedded system has three main components:

- Hardware

- Main application software

- Real Time Operating System (RTOS)

RTOS handles the execution, share resources among processes and schedules the tasks of

the system. A small scale embedded system may not need an RTOS. An embedded system

has software designed to keep in view three constraints; available system memory,

available processor speed and the need to limit power dissipation when running system

continuously.

Embedded system used in this project is small scale embedded systems. These systems are

designed with a single 8 or 16 bit microcontroller; they have little hardware and software

complexities and involve board level design. They may even be battery operated. When

developing embedded software, an editor, assembler and cross assembler, specific to the

microcontroller or processor used, are the main programming tools.

Usually, the C – language is used for developing these systems. Then, program

compilation is done into the assembly, executable codes are then appropriately located in

the system memory. The software has to fit within the memory available and keeping in

view the need to limit power dissipation when system is running continuously.

An embedded system designer has to develop a product using the available tools within the

given specifications, cost and time frame. Full understanding of microcontroller‟s basic

architecture, digital electronics design, software engineering, data communication, control

engineering, sensors and measurements, analog electronic design and PCB design and

manufacture are essential.

Page 33: TRRIIBBHHU UV VAANN TUNNIIVEERRSSIITYY …...Figure 9.2 Simulation of Serial Communication Circuit in Proteus..... 50 Figure 9.3 A Frame Showing the Road Traffic ..... 51 Figure 9.4

21

3.3.1. Microcontroller

A microcontroller is a small computer mounted on a single integrated circuit containing a

processor core, memory and programmable input/output peripherals. Program memory in

the form of NOR flash or OTP ROM is also often included on chip, as well as a typically

small amount of RAM. Microcontrollers are designed for embedded applications, in

contrast to the microprocessors used in personal computers or other general purpose

applications.

Microcontrollers are used in automatically controlled products and devices, such as

automobile engine control systems, implantable medical devices, remote controls, office

machines, appliances, power tools, toys and other embedded systems. By reducing the size

and cost compared to a design that uses a separate microprocessor, memory, and

input/output devices, microcontrollers make it economical to digitally control even more

devices and processes. Mixed signal microcontrollers are common, integrating analog

components needed to control non-digital electronic systems.

A microcontroller can be considered a self-contained system with a processor, memory and

peripherals and can be used as an embedded system. The majority of microcontrollers in

use today are embedded in other machinery, such as automobiles, telephones, appliances,

and peripherals for computer systems. While some embedded systems are very

sophisticated, many have minimal requirements for memory and program length, with no

operating system, and low software complexity. Typical input and output devices include

switches, relays, solenoids, LEDs, small or custom LCD displays, radio frequency devices,

and sensors for data such as temperature, humidity, light level, etc. Embedded systems

usually have no keyboard, screen, disks, printers, or other recognizable I/O devices of a

personal computer, and may lack human interaction devices of any kind.

Courtesy: “Microcontroller” http://en.wikipedia.org/wiki/Microcontroller, 2012

Page 34: TRRIIBBHHU UV VAANN TUNNIIVEERRSSIITYY …...Figure 9.2 Simulation of Serial Communication Circuit in Proteus..... 50 Figure 9.3 A Frame Showing the Road Traffic ..... 51 Figure 9.4

22

4. SYSTEM DEVELOPMENT

4.1. Preliminary investigation phase

4.1.1. Problem in Existing System

Road and traffic engineering is very poor in Nepal. Even the traffic management of the

capital city, Kathmandu is not satisfactory despite the fact that a large number of traffic

personnel are mobilized for the same. Although traffic lights have been installed at various

traffic junctions throughout the city almost all of them are operated as per the

predetermined timing sequence. Hence, an effective traffic management system cannot be

expected.

Even the available traffic light systems are difficult to be maintained by any Nepalese

technician or engineer due to lack of either adequate knowledge or authority to do so. As a

result, once the traffic lights go out of order, they remain non-functional indefinitely.

So, whatever be the reason, the traffic management system has to be switched to manual

mode so as to achieve effective traffic management. In manual mode, the traffic personnel

immediately stand around the centre of the junction and direct the vehicles with hand

gestures to move or stop according to the traffic situation.

In context of Nepal especially in the urban areas, apart from being a very exhaustive job,

the traffic management also brings about the health related problems in the traffic

personnel as the vehicles contribute a lot to air pollution. As a result, there a great need of

automatic traffic control system for effective traffic management.

4.1.2. Application and Scope of Project

During the course of this project, the problems related to the existing traffic management

system of Nepal were identified. In this project, we look forward to solve these problems

by providing an automatic traffic control system that helps to achieve better traffic

management compared to contemporary timer circuit based traffic management. The

automatic system not only reduces the burden of traffic management from the traffic

personnel but also prevents them from being exposed to polluted environment. Apart from

Page 35: TRRIIBBHHU UV VAANN TUNNIIVEERRSSIITYY …...Figure 9.2 Simulation of Serial Communication Circuit in Proteus..... 50 Figure 9.3 A Frame Showing the Road Traffic ..... 51 Figure 9.4

23

this, when traffic management is automated, the traffic personnel can get themselves

involved in other activities such as monitoring whether the vehicles abide by the traffic

rules, look for any particular vehicle that was stolen or was involved in some crime and

likewise.

Furthermore, the system developed in this project has been so designed that it can be easily

maintained by any person (or traffic personnel) who are capable enough to use a computer.

However, repairing or replacing the components of the hardware is not recommended

unless the person doing so has adequate knowledge of microcontroller and electronic

circuits.

4.2. Problem Analysis Phase

4.2.1. Problem Domain

The main purpose of this system is to automatically detect the vehicles present on the road.

Hence, this system needs to accomplish the following tasks to overcome the limitations of

the existing traffic management system:

i. Get sequence of frames from the real-time video of the road traffic.

ii. Detect the number or quantity of vehicles present in each frame using the image

processing algorithms.

iii. Based on the results of image processing, generate appropriate traffic signals that

control the traffic lights using an appropriate interface.

iv. Provide a GUI that helps to monitor the road traffic as well as control the

functioning of overall system.

Page 36: TRRIIBBHHU UV VAANN TUNNIIVEERRSSIITYY …...Figure 9.2 Simulation of Serial Communication Circuit in Proteus..... 50 Figure 9.3 A Frame Showing the Road Traffic ..... 51 Figure 9.4

24

5. METHODOLOGY

5.1. Traffic Detection

Regardless of whether the traffic management system is manual or automatic, the first and

vital step in traffic management is to detect the vehicles present on the road. The extent

upto which vehicles can be detected correctly determines the level of success achieved in

traffic management. Detection through visual observation of roadways has been carried out

since for a long time. Recent development in technologies have shown that traffic detection

through real time video processing, loop detectors, inductive loop sensors and magnetic

sensors has been a noble and a promising approach to automatically detect traffic and its

parameters. [5]

5.1.1. Manual Detection

In manual detection, a traffic personnel or a group of them observe the traffic situation and

depending upon the situation, they take necessary actions to manage the traffic and

eliminate any sort of traffic jams. Although manual detection is efficient upto some extent

compared to the contemporary timer circuit based traffic lights system, it is still a very

tiring job apart from bringing about health related problems, due to air pollution, in the

traffic personnel.

5.1.2. Automatic Detection

Automatic detection of vehicles can be done using the real time video processing, loop

detectors, inductive loop sensors, magnetic sensors, infrared sensors or RFID based

systems. Inductive loop detectors do provide a cost-effective solution, however they are

subjected to a high failure rate when installed in poor road surfaces, decrease pavement life

and obstruct traffic during maintenance and repair. [6] Infrared sensors are affected to a

greater degree by fog than video cameras and cannot be used for effective surveillance. A

system based on Radio-Frequency Identification (RFID) requires that unnecessary extra

hardware to be installed both at every junction and in every vehicle. [6]

Page 37: TRRIIBBHHU UV VAANN TUNNIIVEERRSSIITYY …...Figure 9.2 Simulation of Serial Communication Circuit in Proteus..... 50 Figure 9.3 A Frame Showing the Road Traffic ..... 51 Figure 9.4

25

Among various methods of automatic vehicle detection such as ones mentioned above, the

method implemented in this project is based on digital image processing of the real-time

video of the road traffic. Video-based systems offer many advantages compared to other

automatic vehicle techniques. They provide more traffic information, combine both

surveillance and traffic control technologies, are easily installed, and are scalable with

progress in image processing techniques. [6]

In general, implementation of automatic traffic detection will eliminate the compulsion of

placing traffic personnel at various junctions to detect and manage the traffic.

5.2. Functional Block Diagram of the System

The automatic traffic control system designed in this system typically consists of one or

more cameras, a microprocessor based image processing unit (IPU) for digitizing and

processing the real-time video of the traffic, software for interpreting the video and

deriving appropriate traffic information from it, a microcontroller based decision unit (DU)

that controls the traffic lights and a computer simulation (software) of the control

operations. The entire system establishes a closed loop system with the IPU and the

decision unit forming the closed loop.

The functional block diagram of the system developed in this project is shown in Figure

5.1.

Figure 5.1 Functional Block Diagram of Automatic Traffic Control System

Camera (Input)

Image Processing

Unit

Decision Unit

Traffic Signal

Computer Simulation

Page 38: TRRIIBBHHU UV VAANN TUNNIIVEERRSSIITYY …...Figure 9.2 Simulation of Serial Communication Circuit in Proteus..... 50 Figure 9.3 A Frame Showing the Road Traffic ..... 51 Figure 9.4

26

I) Camera

The camera serves as the major input to the system. This camera can either be a normal

digital camera or special CC camera. During the course of this project, a normal digital

camera has been used to obtain the video footages of the road traffic. The video of the road

traffic acquired by the digital camera is transmitted to the IPU and is used for the analysis

of the traffic conditions.

II) Image Processing Unit

The image processing unit is a microprocessor based system and preferably a laptop or a

PC. This unit stores and runs specific software that obtains the video input of the road

traffic from the camera(s) and implements appropriate image processing algorithms on the

real-time video input(s) so as to extract necessary information about the vehicle traffic.

This software has been designed as an integral part of this project and facilitates to

accomplish the job of DIP. This software has been deliberately developed in such a way

that it does not store the video footages, as the processing is carried out on the real-time

video input(s).

III) Decision Unit

The decision unit follows the IPU and generates the appropriate signals to control the

traffic lights on the basis of the results provided by the IPU. The DU comprises a

microcontroller and ports for serial communication between the IPU and the traffic light

system. Thus, it also serves as an interface between the IPU and the traffic light system.

IV) Traffic Signal

The traffic signal is the major output of this system. The traffic signals are displayed using

the traffic lights.

Page 39: TRRIIBBHHU UV VAANN TUNNIIVEERRSSIITYY …...Figure 9.2 Simulation of Serial Communication Circuit in Proteus..... 50 Figure 9.3 A Frame Showing the Road Traffic ..... 51 Figure 9.4

27

V) Computer Simulation

Computer simulation is another part of the software installed in the IPU. This software is

integrated with the image processing software mentioned above. It shows the real time

images of all the streets of the traffic junction along with the condition of traffic lights for

the respective streets. Thus, it not only enables an operator (or traffic personnel) to monitor

the current traffic condition but also observe whether the traffic lights are being displayed

correctly. Hence, it provides sufficient controls to the operator to switch between automatic

and timing based traffic control. Furthermore, this software also enables the operator to

shutdown or suspend the traffic light system during special conditions such as upon the

arrival of ambulance in emergency from any street or upon the arrival of the vehicles of the

VIP.

5.3. Image Processing Algorithms

Image processing is the backbone of this project. It has been implemented to detect the

vehicles present on the road at any instant under consideration. In context of this project,

the image processing algorithms have been applied to the individual frames of a

continuous real-time video input, which is taken at regular intervals of time. In this system,

the image processing is implemented by the software installed in the IPU.

The image processing algorithms that have been implemented to accomplish the task of

automatic detection of vehicles in this system can be described in reference to the process

diagram shown in Figure 5.2.

5.3.1. Image Acquisition

As explained earlier, a digital camera or a special CC camera is used to obtain the real-time

video of the road traffic. During the development of this project, a normal digital camera

has been used to obtain the video footages of the road traffic. The images or the sequence

of the video frames thus obtained is first converted to grayscale images or video frames.

Page 40: TRRIIBBHHU UV VAANN TUNNIIVEERRSSIITYY …...Figure 9.2 Simulation of Serial Communication Circuit in Proteus..... 50 Figure 9.3 A Frame Showing the Road Traffic ..... 51 Figure 9.4

28

5.3.2. Image Enhancement

After the real-time video is obtained, the individual frames of the video, each of which

represent an image, are pre-processed in order to make them suitable for further

processing. In other words, only certain video frames that are taken after certain interval of

time are processed.

Figure 5.2 DIP Algorithms Used in System Development

Image

Acquisition

Image

Enhancement

Background

Subtraction

Dilation

Thresholding

Extract

Connected

Components

Count Blobs

Vehicle

Detection

Additional Noise

Removal

Thresholding

Count Pixels

Page 41: TRRIIBBHHU UV VAANN TUNNIIVEERRSSIITYY …...Figure 9.2 Simulation of Serial Communication Circuit in Proteus..... 50 Figure 9.3 A Frame Showing the Road Traffic ..... 51 Figure 9.4

29

The pre-processing mainly comprises the image enhancement technique. In case of this

system, histogram equalization followed by median and low-pass Gaussian filtering has

been employed as an image enhancement technique.

5.3.3. Background Subtraction

The main purpose of background subtraction is to remove any static or unnecessary objects

such as nearby buildings, electric poles, etc. from the video frame that do not contribute to

the vehicle detection procedure. Thus, the foreground or the objects of interest i.e. the

vehicles can be extracted from the background in a sequence of video frames.

There are many different methods that can be used for background subtraction, each with

different strengths and weaknesses in terms of performance and computational

requirements. The general procedure of background subtraction comprises preparation of a

background model. To do this, a sequence of video frames that do not contain any object

of interest or foreground (as far as possible) is considered. Then, the necessary information

from the individual frames such as intensity level of each pixel, the frame-by-frame

variation in the intensity level of each pixel, etc. is obtained. After that, all the information

is collectively used to approximate a background model that resembles the actual

background. Now, the sequences of video frames that contain the objects of interest are

considered. These frames are compared with the background model created earlier to

detect any section that does match the background model. This different section represents

the foreground or object of interest. The background subtraction procedure can be

illustrated by Figure 5.3.

Conventional methods of background subtraction require that the camera be free from any

sort of movements. This is needed so that the no any objects of the background are missed

during background modelling. As a result, such objects do not appear as foreground when

the sequences of video frames containing the objects of interest are processed.

Although the camera used to capture the road traffic is not subjected to significant panning,

it still encounters slight jerks when a heavy vehicle or four wheelers pass by the pole to

which it is fixed. As a result, the conventional method of background subtraction is quite

ineffective in case of the system developed in this project. Hence, it became necessary to

Page 42: TRRIIBBHHU UV VAANN TUNNIIVEERRSSIITYY …...Figure 9.2 Simulation of Serial Communication Circuit in Proteus..... 50 Figure 9.3 A Frame Showing the Road Traffic ..... 51 Figure 9.4

30

devise an entirely different approach. After thorough research and findings from hit and

trial, a different method of background subtraction has been employed to process the

images or video frames of the road traffic.

Figure 5.3 Conventional Background Subtraction Procedure

In the method of background subtraction used in this system, the first step is to clip the

image using mathematical modelling approach so that only the section of the frame that

comprises the road along with the vehicles is extracted. This results in the perspective view

of the road (containing vehicles). An example of this procedure is shown in Figures 5.4

and 5.5. Figure 5.4 shows an original frame and Figure 5.5 shows that only the region that

contains the object of interest has been selected for further processing.

The image thus obtained is divided into two different sections – upper and lower halves.

The main purpose of this division is to facilitate the task of vehicle detection using the

image processing algorithms. The region of the image represented by the upper half

contains vehicles in very compact pattern while that represented by the lower half contains

vehicles in quite distinct manner i.e. vehicles can be identified quite clearly than in upper

half. These characteristics can be observed in the Figure 5.4. Hence, two different methods

of DIP have to be implemented to process these two halves.

Video Input with No Object of Interest (as far as

possible)

Prepare Background Model

Video Input with Object of Interest

Compare Individual Frames with Background Model

Detect Foreground or Object of Interest

Page 43: TRRIIBBHHU UV VAANN TUNNIIVEERRSSIITYY …...Figure 9.2 Simulation of Serial Communication Circuit in Proteus..... 50 Figure 9.3 A Frame Showing the Road Traffic ..... 51 Figure 9.4

31

Figure 5.4 Original Image

Figure 5.5 Image With Only Objects of Interest

Considering Figure 5.5, the actual image i.e. image with only objects of interest is divided

into two halves along its centre. This process is shown in Figures 5.6 and Figure 5.7.

The two halves of the image thus obtained are processed in two different ways but

simultaneously.

Page 44: TRRIIBBHHU UV VAANN TUNNIIVEERRSSIITYY …...Figure 9.2 Simulation of Serial Communication Circuit in Proteus..... 50 Figure 9.3 A Frame Showing the Road Traffic ..... 51 Figure 9.4

32

Figure 5.6 Upper Half Portion

Figure 5.7 Lower Half Portion

The processing of the two halves of the images as obtained in Figures 5.6 and 5.7 is done

in the following steps.

5.3.4. Processing Upper Half of the Image

I) Additional Noise Removal

The additional noise removal algorithm is mainly implemented to remove bright spots

from the image. These spots lead to the false calculation of vehicle density. So these kinds

of high frequency noises are removed by applying the low-pass Gaussian (smoothing)

filter. These noises mostly occur due to poor quality of camera or even due to the

unfavourable lighting conditions.

Page 45: TRRIIBBHHU UV VAANN TUNNIIVEERRSSIITYY …...Figure 9.2 Simulation of Serial Communication Circuit in Proteus..... 50 Figure 9.3 A Frame Showing the Road Traffic ..... 51 Figure 9.4

33

II) Thresholding

The image obtained after the Gaussian filtering is subjected to the segmentation process

based on thresholding method. In this method, the threshold value is taken to be little bit

higher (around 40 and obtained through experimentation) than the mean value of the

image.

Thus, the image obtained after threshold is a binary image which has only completely

white and black regions and no any intermediate values.

Figure 5.8 Thresholded Image

III) Count Number of Pixels

Finally, the pixels that have non-zero intensity values present in the resulting image are

counted. The counting is such that in the upper region, less number of pixels corresponds

to one vehicle and on moving towards the lower region of the image, relatively more

number of pixels corresponds to one vehicle.

As a mathematical modelling approach has been adopted, the vehicles that are near to the

camera appear to be illuminated relatively more than those that are far from the camera.

Hence, they dominate the vehicles farther from the camera in the image and the vehicle

counting is adversely affected.

Figure 5.9 Clipping with Lines to get the Proper Count of Vehicle in the Image

Page 46: TRRIIBBHHU UV VAANN TUNNIIVEERRSSIITYY …...Figure 9.2 Simulation of Serial Communication Circuit in Proteus..... 50 Figure 9.3 A Frame Showing the Road Traffic ..... 51 Figure 9.4

34

5.3.5. Processing Lower Half of the Image

I) Dilation

Dilation operation has been used in order to highlight any vehicle, especially ones with

brighter colour that are present on the lower half of the image being processed.

The result of dilation operation on the image shown in Figure 5.7 is illustrated in Figure

5.10.

Figure 5.10 Dilated Image

II) Thresholding

Thresholding has been applied to separate only the brighter objects from the image. The

darker objects are treated as the background and suppressed so that they are not considered

for further processing.

Figure 5.11 Thresholded Image

III) Extract Connected Components

After the thresholding operation has been carried out, the connected components from the

resulting image are extracted assuming that these components represent vehicles. The

connected components are extracted in the form of white blobs.

Page 47: TRRIIBBHHU UV VAANN TUNNIIVEERRSSIITYY …...Figure 9.2 Simulation of Serial Communication Circuit in Proteus..... 50 Figure 9.3 A Frame Showing the Road Traffic ..... 51 Figure 9.4

35

IV) Count Number of Blobs

The number of blobs present in the image of interest is counted using an iterative algorithm.

Finally the number of blobs gives the number of vehicles present in the region of interest

determined by the lower half of the original frame.

The results regarding the number or quantity of vehicles from both halves are combined so

as to finally obtain the number or quantity of vehicles present on the road. This vehicle

count is supplied to the decision unit and simulation software unit to control the timing of

the traffic lights for each road.

Page 48: TRRIIBBHHU UV VAANN TUNNIIVEERRSSIITYY …...Figure 9.2 Simulation of Serial Communication Circuit in Proteus..... 50 Figure 9.3 A Frame Showing the Road Traffic ..... 51 Figure 9.4

36

6. HARDWARE IMPLEMENTATION

Figure 6.1 Block Diagram of Hardware Implementation

6.1. Control Interface

The control interface is the main interface circuit between the microcontroller, traffic lights,

and PC. The control interface used during this project is custom designed and self-fabricated

PIC16F877A (pin diagram shown in Appendix B) microcontroller based system. The inputs to

the control interface are the control signals from PC. Similarly, the outputs from the control

interface are the control signals to the traffic lights and data signals to PC. The operating

frequency of the crystal oscillator for PIC16F877A microcontroller is 11.0592MHz.

6.1.1. Specification of Control Interface

The control interface designed in this project is basically a microcontroller based system.

The specifications of this control interface are as follows:

i. Microchip PIC16F877A microcontroller used.

ii. Serial interface using MAX232 (pin diagram shown in Appendix C) for

communication between PC and the microcontroller.

iii. Interfacing of traffic lights unit.

iv. There is no effect on the operation of the control interface regardless of the polarity

of power at the input.

v. The control circuit consists of ULN 2803A (pin diagram shown in Appendix D) ICs

for the purpose of the current amplification.

vi. The control interface consists of bar graphs in order to monitor the status of the

pins.

IPU Control Interface Traffic Lights

Page 49: TRRIIBBHHU UV VAANN TUNNIIVEERRSSIITYY …...Figure 9.2 Simulation of Serial Communication Circuit in Proteus..... 50 Figure 9.3 A Frame Showing the Road Traffic ..... 51 Figure 9.4

37

Figure 6.2 KiCAD Design of Control Interface

6.2. Communication with PC

RS232 serial data communication protocol has been used to establish communication

between the PC and the microcontroller board. The method is also applied for

programming PIC16F877A through boot-loader by accessing its TX and RX pins.

MAX232 IC works as an interface between the TTL and RS232 standards as shown in

Figure 6.2. A USB to RS232 cable has been used to connect the USB port of PC to the

DB9 port of control interface board.

Page 50: TRRIIBBHHU UV VAANN TUNNIIVEERRSSIITYY …...Figure 9.2 Simulation of Serial Communication Circuit in Proteus..... 50 Figure 9.3 A Frame Showing the Road Traffic ..... 51 Figure 9.4

38

6.3. Current Amplifier

The current provided by the microcontroller alone is not enough to light the LED used as

the traffic lights. So, in order to fulfil the current requirement of the LED the current

amplification is needed, which has been carried out by the help of the Darlington transistor.

The Darlington transistor (often called a Darlington pair) is a compound structure

consisting of two bipolar transistors (either integrated or separated devices) connected in

such a way that the current amplified by the first transistor is amplified further by the

second one. This configuration gives a much higher common-emitter current gain than

each transistor taken separately and, in the case of integrated devices, can take less space

than two individual transistors because they can use a shared collector. Integrated

Darlington pairs are available in transistor-like packages or as an array of devices (usually

eight) in an integrated circuit. [8] A Darlington pair behaves like a single transistor with a

high current gain (approximately the product of the gains of the two transistors).

Darlington pair of transistor is also called as super-beta transistor. It has the capacity to

amplify the current output many a times than a normal transistor configuration.

A general relation between the compound current gain and the individual gains is given by:

[8]

(5.1)

If β1 and β2 are high enough (in order of hundreds mA), this relation can be approximated

with Equation 5.2.

(5.2)

Figure 6.3 Circuit Diagram of a Darlington Pair using NPN Transistors

Page 51: TRRIIBBHHU UV VAANN TUNNIIVEERRSSIITYY …...Figure 9.2 Simulation of Serial Communication Circuit in Proteus..... 50 Figure 9.3 A Frame Showing the Road Traffic ..... 51 Figure 9.4

39

The microcontroller triggers the base of the Darlington amplifier. The LED is connected

between the source and the collector of the Darlington. The amplified current flows

through the LED and it glows.

Figure 6.4 LED Connections Using Darlington Pair

Darlington pairs are available as integrated packages. The integrated package of Darlington

pairs used in the control interface of the system developed in this project is ULN 2083A.

The ULN2803A is a high-voltage, high-current Darlington transistor array. The device

consists of eight NPN Darlington pairs that feature high-voltage outputs with common-

cathode clamp diodes for switching inductive loads. The collector-current rating of each

Darlington pair is 500 mA. The Darlington pairs may be connected in parallel for higher

current capability.

Courtesy: “Darlington transistor” http://en.wikipedia.org/wiki/Darlington_transistor, 2012

6.4. Traffic Lights Circuit

The traffic light circuit is a simple circuit containing 9 LEDs.

Page 52: TRRIIBBHHU UV VAANN TUNNIIVEERRSSIITYY …...Figure 9.2 Simulation of Serial Communication Circuit in Proteus..... 50 Figure 9.3 A Frame Showing the Road Traffic ..... 51 Figure 9.4

40

i. One red LED for the red signal of the traffic light.

ii. One amber LED for the amber signal of the traffic light.

iii. One green LED for the green signal of the traffic light.

iv. A group of 6 white LEDs form an arrow (shown in Figure 6.5) to show the „right-

turn‟.

This circuit consists of 5 connectors. Four connectors for each LED making connection to

the collector pins of the ULN 2803A through the 220 ohm resistor. The fifth connector

connects the anode of the LED with the 5V DC supply to each LEDs.

There are total 8 traffic lights circuits installed in the system. Two traffic light circuits are

installed for each direction. These circuits are connected to the collector of the ULN

2803A on the control interface with the help of connectors.

Figure 6.5 PCB Design of Traffic Light Circuit

6.5. Tools Used for Simulation

6.5.1. Proteus VSM

The Proteus VSM combines mixed mode SPICE circuit simulation, animated components

and microcontroller models to facilitate co-simulation of complete microcontroller based

design. It is possible to develop and test such designs before a physical prototype is

constructed. This is possible because interaction with the design is possible using circuit

indicators like LED, display panels, actuators etc. It also provides extensive debugging

Page 53: TRRIIBBHHU UV VAANN TUNNIIVEERRSSIITYY …...Figure 9.2 Simulation of Serial Communication Circuit in Proteus..... 50 Figure 9.3 A Frame Showing the Road Traffic ..... 51 Figure 9.4

41

facility by employing breakpoints, single stepping and variable display of both assembly

code and high level language source code.

6.5.2. Livewire

Livewire is a CAD product developed by New Wave Concepts. It allows the user to create

and simulate electronic circuits using an extensive gallery of circuit components. Switches,

transistors, diodes, integrated circuits and hundreds of other components can all be

connected together to investigate the behaviour of a circuit. There are no limits to what can

be designed and any loose connections or faulty components to worry about.

The finished circuit can be exported into sister-program PCB Wizard in order to route it for

a PCB design.

6.6. Tools used for Circuit Design

6.6.1. PCB Wizard

The PCB Wizard is a powerful and a highly innovative package for designing single side

and double side PCBs. It provides a comprehensive range of tools covering all the

traditional steps in PCB production, including schematic drawing, schematic capture,

component placement, automatic routing. Circuit diagrams are drawn using circuit symbol

components connected with wires. Components are simply dragged, dropped and arranged

in the working window and necessary connections are made between the component

terminals.

6.6.2. KiCAD

KiCAD is an open source software suite for electronic design automation. It facilitates the

design of schematics for electronic circuits and their conversion to PCB designs. KiCAD

uses an integrated environment for all of the stages of the design process – schematic

capture, PCB layout, Gerber file generation/visualization and library editing. KiCAD has a

Page 54: TRRIIBBHHU UV VAANN TUNNIIVEERRSSIITYY …...Figure 9.2 Simulation of Serial Communication Circuit in Proteus..... 50 Figure 9.3 A Frame Showing the Road Traffic ..... 51 Figure 9.4

42

built-in basic auto router. Tools exist within the package to create artwork and 3D view of

the PCB. KiCAD is also a cross platform.

6.7. Tools used for Microcontroller Programming

6.7.1. MPLAB

MPLAB IDE is a program that runs on a PC to develop applications for microchips,

microcontrollers and digital signal controllers. The IDE provides a single integrated

environment to develop code for embedded microcontroller. The compiler associated with

the IDE compiles the high level C code and corresponding hex code is generated. The

compiler can optimize high level C code, eliminate code that will never be executed, share

common code fragments among multiple functions and can identify data and registers that

are used inefficiently optimizing their access. The MPLAB graphical user interface serves

as a single environment to write, compile and debug for embedded applications.

Page 55: TRRIIBBHHU UV VAANN TUNNIIVEERRSSIITYY …...Figure 9.2 Simulation of Serial Communication Circuit in Proteus..... 50 Figure 9.3 A Frame Showing the Road Traffic ..... 51 Figure 9.4

43

7. SOFTWARE IMPLEMENTATION AND SIMULATION

7.1. Programming Language and Tools

i. Language: C and C++

C is a general-purpose programming language initially developed by Dennis

Ritchie between 1969 and 1973 at Bell Labs. C++ is a statically typed, free-form,

multi-paradigm, compiled, general-purpose programming language.

Courtesy: “C (programming language)” http://en.wikipedia.org/wiki/C_(programming_language)

“C++” http://en.wikipedia.org/wiki/C%2B%2B

ii. Image Processing Library: OpenCV version 2.1 (details in Appendix D)

iii. IDE: Qt Creator version 2.0.1 has been used as the IDE. (details in Appendix E)

7.2. Simulation Software/GUI

The simulation software is more or less a GUI of the system developed in this project that

carries out the necessary image processing algorithms on the sequence of video frames of

the road traffic. Apart from this, this software also provides a user friendly environment

that facilitates the traffic surveillance as well as enables the operator or traffic personnel to

observe and control the functioning of the traffic lights system. The simulation software is

run on an IPU which may be situated at a remote location that need not be near to the

traffic junction being managed. However, it must be made sure that the video transmission

of the traffic junction to the IPU must be continuous and should not be disturbed by abrupt

power cuts or similar other problems.

The GUI is operated only by the authorized traffic personnel from the control room. As the

traffic personnel can view the real-time traffic situations of the traffic junction being

considered, he/she can switch from the automatic to the manual mode very easily. As

explained earlier, in manual mode the traffic lights can be manually controlled one traffic

light from each traffic light arrangement at a time. Thus, he/she can take necessary actions

to solve the traffic deadlock conditions or any other condition that cannot be solved by this

automated system such as prioritizing the ambulances, fire-engines or the vehicles of the

VIPs.

Page 56: TRRIIBBHHU UV VAANN TUNNIIVEERRSSIITYY …...Figure 9.2 Simulation of Serial Communication Circuit in Proteus..... 50 Figure 9.3 A Frame Showing the Road Traffic ..... 51 Figure 9.4

44

After the program is installed and run, the actual operation is begun after the “Start” button

as shown in Figure 7.1 has been clicked. The circles of each colour shown in the figure

represent the corresponding traffic lights.

Figure 7.1 Screenshot of the GUI

The program can be run in two modes – automatic and manual modes.

I) Automatic Mode

In automatic mode, the following features are available:

i. Fixed Timing System

In this system, the traffic lights are changed in certain standard order after every fixed

interval of time. This feature is applicable for automatic traffic control especially

during the morning and late night when there is less traffic density.

ii. Image Processing System

In this system, the traffic lights are changed in accordance with the density of vehicles

in each street which is determined by the DIP of the sequence of video frames of the

vehicle traffic of each road.

Page 57: TRRIIBBHHU UV VAANN TUNNIIVEERRSSIITYY …...Figure 9.2 Simulation of Serial Communication Circuit in Proteus..... 50 Figure 9.3 A Frame Showing the Road Traffic ..... 51 Figure 9.4

45

II) Manual Mode

In manual mode, the traffic personnel can alter the order in which the traffic lights are

illuminated under normal conditions so as to keep up with the existing traffic scenario.

This mode is executed under special conditions such as during the arrival of ambulances or

fire-engines in any lane that does not have the priority to be served at that instant.

The altered traffic light arrangements can take any one of the following eight states:

i. Green-Red-Red-Red

ii. Yellow-Red-Red-Red

iii. Red-Green-Red-Red

iv. Red-Yellow-Red-Red

v. Red-Red-Green-Red

vi. Red-Red-Yellow-Red

vii. Red-Red-Red-Green

viii. Red-Red-Red-Yellow

Page 58: TRRIIBBHHU UV VAANN TUNNIIVEERRSSIITYY …...Figure 9.2 Simulation of Serial Communication Circuit in Proteus..... 50 Figure 9.3 A Frame Showing the Road Traffic ..... 51 Figure 9.4

46

8. PROBLEM FACED AND SOLUTIONS

8.1. Some Solved Problems

8.1.1. Software

i. Background Subtraction

The conventional background subtraction method proved to be inefficient in case of

the video footages that are to be processed by the system developed in this project.

So, a different background subtraction method has been devised to overcome this

problem. This method exploited the feature of perspective distortion of the video

frames.

ii. Detection of Vehicles Far Away from the Traffic Junction

It was difficult to detect the vehicles that were far away from the traffic junction.

This problem is solved by considering the differential intensity values of the

adjacent pixels in the section of the video frame corresponding to the region

situated far away from the traffic junction.

8.1.2. Hardware

i. Data Transmission between the IPU and Control Interface

As the microcontroller PIC16F877A has been used, either serial or parallel

communication technique for data transmission could be implemented. Since the

serial communication is far better than the parallel communication, the data transfer

or transfer of control signals between the IPU (or PC) and the control interface of

this system is established by asynchronous serial communication.

ii. Loss in Data Transmitted

Since the serial communication is very prone to bit loss during data transmission,

the bits are sometimes lost during transmission which may generate wrong

information at the receiving end. This problem is solved by using the proper cable

which is verified through experimentation.

Page 59: TRRIIBBHHU UV VAANN TUNNIIVEERRSSIITYY …...Figure 9.2 Simulation of Serial Communication Circuit in Proteus..... 50 Figure 9.3 A Frame Showing the Road Traffic ..... 51 Figure 9.4

47

8.2. Some Unsolved Problems

8.2.1. Software

Bright Spots or Lines on the Road

The white spots or lines that have been painted by the Metropolitan Traffic Police Division

or Department of Road and Department of Transport Management present on the road

grow brighter after the dilation operation. As a result, they give rise to extremely distinct

blobs which are also detected as vehicles.

Page 60: TRRIIBBHHU UV VAANN TUNNIIVEERRSSIITYY …...Figure 9.2 Simulation of Serial Communication Circuit in Proteus..... 50 Figure 9.3 A Frame Showing the Road Traffic ..... 51 Figure 9.4

48

9. RESULT AND ANALYSIS

9.1. Experimental Setup

The simulation software is installed on an IPU to begin the process of vehicle detection.

The continuous video inputs of the road traffic are provided to the IPU. The power supply

to the interface module is properly connected.

9.2. Hardware Testing

The process of hardware testing has been done in several phases to ensure the proper

working of the embedded system.

9.2.1. Basic Circuit Testing

This phase of the hardware testing includes the following tests:

i. Short circuit test between Vcc and ground.

ii. Checking the polarity of the capacitors and diodes.

iii. Checking the output of the 7805 regulator.

iv. Connectivity testing.

v. Testing the response of microcontroller, MAX 232 and ULN 2803A.

vi. Testing the bar-graph and LEDs.

9.2.2. Testing the Fixed Time System

In this test, the hardware of the system developed in this project was simulated in the

Proteus VSM. The Proteus simulation and testing helps to know whether the concept of the

corresponding hardware is feasible to implement or not. Although it does not certainly

guarantee that circuit will work, it still gives an idea about the working of the system.

The program for the fixed time traffic system was written and then loaded in the

microcontroller. The control interface was tested with the help of this program. The

response of the system was observed in the bar-graph.

Page 61: TRRIIBBHHU UV VAANN TUNNIIVEERRSSIITYY …...Figure 9.2 Simulation of Serial Communication Circuit in Proteus..... 50 Figure 9.3 A Frame Showing the Road Traffic ..... 51 Figure 9.4

49

9.2.3. Testing the Traffic Light Circuit

The traffic light circuit was tested by connecting the connector connected to the anode of

LED (traffic signs) via 220 ohm resistors to 5V DC supply and by connecting the

connector connected to the cathode of the LED (traffic signs) to the ground. It was tested

whether the lights were turned on or not. If the light was not illuminated, then the problem

was searched. Generally, the problem was due to either the faulty LEDS or the lack of the

proper connection in the circuit.

Figure 9.1 Simulation of Traffic Light Circuit in Proteus

9.2.4. Connecting the Control Interface and Traffic Light Circuit

After successfully passing the tests of the above phases, the two basic units of this

embedded system were connected together and tested. The program for the fixed time

system was loaded in the microcontroller. The traffic light circuits were connected to the

control interface with the pins placed at the collector of the ULN 2083A. The system

response was observed and corrected in case of problems. The only problem in this phase

was that some of the traffic signs didn‟t respond as they should have. The reason was lack

of proper connection between the traffic light circuit and the control interface. The proper

connection was made between those circuits at the end of this phase.

Page 62: TRRIIBBHHU UV VAANN TUNNIIVEERRSSIITYY …...Figure 9.2 Simulation of Serial Communication Circuit in Proteus..... 50 Figure 9.3 A Frame Showing the Road Traffic ..... 51 Figure 9.4

50

9.2.5. Connecting Control Interface and PC

The control interface and PC were connected to each other with the help of the USB to RS

232 connector. The USB to serial communication was tested. The data was sent from the

PC to the control interface and the response was observed. The data was also sent form the

microcontroller to the PC and it was checked whether the data reached to the PC or not.

Figure 9.2 Simulation of Serial Communication Circuit in Proteus

9.2.6. Connecting All Three Units and Testing

This was the sixth and the last phase in the process of the hardware testing. In this phase,

all the three units of the system were connected to each other and tested. The data was sent

from PC to the microcontroller placed on the control interface via USB to RS232 cable

(figure in Appendix C). The response of the microcontroller was observed in the bar-graph

and the traffic light circuits. The feedback was also sent to the PC by the microcontroller.

This feedback gives the status of the embedded system. The feedback data were compared

to the data sent initially by the PC to make sure that the system was working properly. At

the end of this phase the proper health of the hardware of the system was verified.

Page 63: TRRIIBBHHU UV VAANN TUNNIIVEERRSSIITYY …...Figure 9.2 Simulation of Serial Communication Circuit in Proteus..... 50 Figure 9.3 A Frame Showing the Road Traffic ..... 51 Figure 9.4

51

9.3. Software Testing

For the purpose of software testing, as the actual video footages of the road traffic that are

captured by the CC camera of the traffic department were not available, we had to go to the

actual locations and get the required video footages.

The video footages were captured under favourable lighting conditions and during the

daytime. Most of the tests were performed by using the individual frames of the video

footages.

After debugging both the hardware and software of this system, the video footages of the

road traffic captured by us were evaluated. Certain frames of those video files were

processed individually to test the performance of the system. These video frames were

modified with respect to the lighting conditions and degree of noise before they were

subjected to testing. The figures – Figure 9.3 shows the one of such frames and Figure 9.4

shows the screenshot of GUI that shows the number of vehicles (approximately) present on

the road. The GUI shows that 47 vehicles are present in the frame of the video footage

shown by Figure 9.3.

Figure 9.3 A Frame Showing the Road Traffic

Page 64: TRRIIBBHHU UV VAANN TUNNIIVEERRSSIITYY …...Figure 9.2 Simulation of Serial Communication Circuit in Proteus..... 50 Figure 9.3 A Frame Showing the Road Traffic ..... 51 Figure 9.4

52

Figure 9.4 Section of GUI Showing the Number of Vehicles

Similarly, the vehicle count for three other roads was calculated. Then, by comparing the

number of vehicles counted and on the basis of the traffic engineering theory described in

section 3.1, the green phase for the each road is determined and the necessary control

signals are transmitted to the decision unit (microcontroller) via serial communication.

These signals are decoded to illuminate the traffic light interfaced in the control interface.

For the purpose of this project and considering the scenario of traffic system in Nepal, the

order of illuminating the traffic lights in this system is quite different from that described

in section 3.1.

Page 65: TRRIIBBHHU UV VAANN TUNNIIVEERRSSIITYY …...Figure 9.2 Simulation of Serial Communication Circuit in Proteus..... 50 Figure 9.3 A Frame Showing the Road Traffic ..... 51 Figure 9.4

53

10. COST ANALYSIS OF THE PROJECT

The total expenditure done in favour of the project right from its initiation upto its

completion has been summarized in following table:

S. No. Item Specification Rate (Rs.) Quantity Total (Rs.)

1 Hydrogen Peroxide - 20 2 40

2 DB9 Female 25 1 25

3 Multi-adapter - 150 1 150

4 ULN 2803 - 35 4 140

5 DC Socket - 15 1 15

6 USB Socket Female 15 1 15

7 Soldering Rod Bit 40 Watt 75 1 75

8 DC Soldering Rump - 275 1 275

9 Ribbon Wire - 25 2 50

10 Capacitors 1000 µF 15 2 30

11 Capacitors 100 µF 16 2 32

12 Capacitors 10 µF 4 3 12

13 Capacitors 0.1 µF 10 1 10

14 Push Button - 5 1 5

15 11.0592 MHz Crystal - 35 1 35

16 IC Base - 10 5 50

17 40-pin Base - 40 1 40

18 MAX 232 - 125 2 250

19 7805 - 15 1 15

20 4007 - 10 1 10

21 PCB(12"x12") - 700 2 1400

22 6-pin Relimate (I) - 20 32 640

23 Network Resistors - 10 6 60

25 Drill Bit 1mm - 20 2 40

26 PIC 16F877A - 500 2 1000

Page 66: TRRIIBBHHU UV VAANN TUNNIIVEERRSSIITYY …...Figure 9.2 Simulation of Serial Communication Circuit in Proteus..... 50 Figure 9.3 A Frame Showing the Road Traffic ..... 51 Figure 9.4

54

S. No. Item Specification Rate (Rs.) Quantity Total (Rs.)

27 10-pin Male Relimate - 20 10 200

28 Ribbon Cable 1 metre 100 10 1000

29 Resistor 10 k 0.7 150 105

30 Resistor 1 k 0.8 50 40

31 74 LS 153 - 80 2 160

32 LED - - 63 170

33 Conc. HCL 250 ml 500 1 500

34 Acetone 250 ml 300 1 300

35 Dip-switch - 200 2 400

36 Bar-graph - 300 2 600

37 Miscellaneous - 1500 1 1500

Grand Total 9389

Table 9.1 Cost Analysis of the Project

Page 67: TRRIIBBHHU UV VAANN TUNNIIVEERRSSIITYY …...Figure 9.2 Simulation of Serial Communication Circuit in Proteus..... 50 Figure 9.3 A Frame Showing the Road Traffic ..... 51 Figure 9.4

55

11. LIMITATIONS AND FUTURE ENHANCEMENTS

11.1. Limitations

Despite the fact that some of the problems found in the existing traffic management system

of Nepal have been successfully addressed in this project, there are still some limitations in

the system developed in this project. The limitations of this system are as follows:

i. The cameras used to shoot the road traffic should be placed at sufficiently higher

position than the average height of the heavy vehicles such as bus, truck, etc.

ii. The camera should be aligned in such a way that its direction of observation aligns

with the road being observed as far as possible.

iii. The developed system should be used to detect the vehicles in robust

environmental conditions.

iv. This system may not respond well under unfavourable lighting conditions such as

during gloomy days or in poorly illuminated environments.

v. This system is unsuitable for use during night time.

vi. This system doesn‟t make the exact count of the number of vehicles present but

gives a relative estimation of volume of the vehicles in the road.

vii. This system has been developed considering the crossroads to run straight from the

traffic junction with no changes in inclination. Hence, it may need to be modified

in order to be used for curved and inclined roads.

viii. The developed system is unsuitable to detect the ambulances or fire-engines that

are in emergency.

11.2. Future Enhancements

i. This system can be further developed to detect the ambulances or fire-engines on

the basis of their siren by integrating the audio processing mechanisms or by

integrating the RFID approach to the present system.

ii. All the transmissions in and out of the system developed in this project are wired.

Hence, a wireless traffic control system can be developed.

Page 68: TRRIIBBHHU UV VAANN TUNNIIVEERRSSIITYY …...Figure 9.2 Simulation of Serial Communication Circuit in Proteus..... 50 Figure 9.3 A Frame Showing the Road Traffic ..... 51 Figure 9.4

56

iii. Advanced image processing algorithms and libraries could be used so that the

system can be used efficiently even during unfavourable lighting conditions and

during the night time as well.

iv. Further improvements can be made so that the system can determine the exact

number of vehicles in the road.

v. This system can be developed to read the numbers on the number plates of the

vehicles and keep the record.

vi. Microcontroller can be replaced by Field Programmable Gate Array (FPGA) as it

has many advantages over microcontroller regarding the speed, number of I/O ports

and performance.

Page 69: TRRIIBBHHU UV VAANN TUNNIIVEERRSSIITYY …...Figure 9.2 Simulation of Serial Communication Circuit in Proteus..... 50 Figure 9.3 A Frame Showing the Road Traffic ..... 51 Figure 9.4

57

12. CONCLUSION

The project “Automatic Traffic Control System using Digital Image Processing” aims at

automating the traffic management system. Although this system is not unique, it is an

upgrade to the similar systems developed in earlier projects.

The system emphasizes on the DIP algorithms for the detection of vehicles in the road. By

integrating the DIP in software with the necessary hardware to control the traffic lights, the

required automatic traffic control system has been developed. During the process of

development, many research works and papers carried out in the respective fields were

thoroughly studied. Based on the results and conclusions provided by such papers, the

algorithms that best addressed the problem domain of this project were selected.

This project has not been tested in the actual field although the performance of the system

for the video footages of the actual field was evaluated and quite satisfactory results were

obtained. Hence, some modifications or changes might still be needed before it is tested in

the actual field. As it has been explained in the sections 11.1 and 11.2, there are still a few

limitations that are to be overcome and few other enhancements that can be made in this

system so that it can be effectively launched in the actual field.

Page 70: TRRIIBBHHU UV VAANN TUNNIIVEERRSSIITYY …...Figure 9.2 Simulation of Serial Communication Circuit in Proteus..... 50 Figure 9.3 A Frame Showing the Road Traffic ..... 51 Figure 9.4

58

13. REFERENCES

[1] N. S. Kumar, M. Saravanan and S. Jeevananthan, Microprocessors and

Microcontrollers, 5th

Edition, Oxford University Press, 2012

[2] G. Singh, Highway Engineering, 5th

Edition, Standard Publishers Distributors, 2006

[3] R. C. Gonzalez and R. E. Woods, Digital Image Processing, 3rd

Edition

[4] G. Bradski and A. Kaehler, O’ Reilly Learning OpenCV, 1st Edition, O‟Reilly Media,

Inc., 2008

[5] H. T. Thi, A Robust Traffic Surveillance System for Detecting and Tracking Vehicles

at Night-time, University of Technology, Sydney, Faculty of Engineering, Nov 21,

2007

[6] V. Dangi, A. Parab, K. Pawar and S. S. Rathod, Image Processing Based Intelligent

Traffic Controller, Electronics and Telecommunication Dept., Sardar Patel Institute

of Technology, Mumbai, India

[7] A.K. Jain, Fundamentals of Digital Image Processing, Prentice-Hall, 1989.

[8] M. Bramberger, R. P. Pflugfelder, A. Maier, B. Rinner and B. Strobl, A Smart

Camera for Traffic Surveillance, Institute for Technical Informatics, Graz University

of Technology, Graz, Austria

[9] Mrs. S. Mehta, Fuzzy Control System for Controlling Traffic Lights, proceedings of

the International Multi Conference of Engineers and Computer Scientists 2008 Vol I

IMECS 2008, 19-21 March, 2008, Hong Kong

[10] I. Jain and B. Rani, Vehicle Detection Using Image Processing and Fuzzy Logic,

International Journal of Computer Science and Communication, Vol. 1, No. 2, July-

December 2010.

[11] Y. Liu and P. Payeur, Robust Image-based Detection of Activity for Traffic Control,

Vision, Imaging, Video and Audio Research Laboratory, School of Information

Technology and Engineering, University of Ottawa.

[12] E. de la Rocha and R. Palacios, Image Processing Algorithms for Detecting and

Counting Vehicles Waiting at a Traffic Light, Journal of Electronic Imaging,

October-December 2010

[13] S. Johnsen and A. Tews, Real Time Object Tracking and Classification using a Static

Camera, proceeding of the IEEE ICRA 2009, workshop on people detection and

tracking, Kobe, Japan, May 2009

Page 71: TRRIIBBHHU UV VAANN TUNNIIVEERRSSIITYY …...Figure 9.2 Simulation of Serial Communication Circuit in Proteus..... 50 Figure 9.3 A Frame Showing the Road Traffic ..... 51 Figure 9.4

59

[14] M. Sivabalakrishnan and Dr. D. Manjula, An Efficient Foreground Detection

Algorithm for Visual Surveillance System, International Journal of Computer Science

and Network Security, Vol-9, No. 5, May 2009.

[15] M. Fathy and M. Y. Siyal, A Window-Based Edge Detection Technique for

Measuring Road Traffic Parameters in Real-Time, Real-Time Imaging 1, pp. 297-

305, Academic Press, 1995.

[16] M. Fathy and M. Y. Siyal, An Image Detection Technique Based on Morphological

Edge Detection and Background Differencing for Real-Time Traffic Analysis, Pattern

Recognition Letters, Vol. 16 (1995), pp. 1321-1330.

[17] S. Umbaugh, Computer Vision and Image Processing, Prentice Hall, NJ, 1998

[18] “Dilation”

http://homepages.inf.ed.ac.uk/rbf/HIPR2/dilate.htm, 2012

[19] “Traffic light”

http://en.wikipedia.org/wiki/Traffic_light, 2012

Page 72: TRRIIBBHHU UV VAANN TUNNIIVEERRSSIITYY …...Figure 9.2 Simulation of Serial Communication Circuit in Proteus..... 50 Figure 9.3 A Frame Showing the Road Traffic ..... 51 Figure 9.4

60

APPENDIX

Appendix A

Cycle Length

It is time taken for one complete sequence of signal indications. This time falls between 40

and 120 seconds. In order to reduce delay to standing traffic, short cycle lengths are

preferred. The cycle length is designed in such a way that the waiting traffic queues should

not become unnecessarily long.

Phase

It is a part of the cycle length allocated for specific movement.

Interval

The time for which signal continues to reflect the same coloured light in a cycle is called

interval.

Page 73: TRRIIBBHHU UV VAANN TUNNIIVEERRSSIITYY …...Figure 9.2 Simulation of Serial Communication Circuit in Proteus..... 50 Figure 9.3 A Frame Showing the Road Traffic ..... 51 Figure 9.4

61

Appendix B

Pin Diagram of PIC 16F877A

Page 74: TRRIIBBHHU UV VAANN TUNNIIVEERRSSIITYY …...Figure 9.2 Simulation of Serial Communication Circuit in Proteus..... 50 Figure 9.3 A Frame Showing the Road Traffic ..... 51 Figure 9.4

62

Appendix C

An interfacing standard called RS-232 standard allows compatibility among data

communication equipments made by various manufacturers. It is the most widely used

serial I/O interfacing standard.

The connector used is either DB-25 connector or DB-9 connector. In labeling, DB-25P

refers to the plug connector (male) and DB-25S is for the socket connector (female). The

maximum length of cable between the receiver and transmitter should not exceed 100 feet

and the maximum cable capacitance is 2500 Pico farad.

Terminal to Computer RS-232 Interface

Since this standard was set long before the advent of the Transistor–Transistor Logic

(TTL) logic family, its input and output voltage levels are not TTL compatible. The TTL

logic used by microcontroller is +12V for logic 0 and -12V for logic 1 while in RS-232 a

logic 1 is represented by -3V to -25V and a logic 0 is represented by +3V to +25V.

To connect any RS-232 to a microcontroller system, converters such as MAX232, also

called as line drivers, are needed to convert the TTL logic levels to the RS-232 voltage

levels and vice-versa. One advantage of MAX232 chips is that it uses a +5V power source

Page 75: TRRIIBBHHU UV VAANN TUNNIIVEERRSSIITYY …...Figure 9.2 Simulation of Serial Communication Circuit in Proteus..... 50 Figure 9.3 A Frame Showing the Road Traffic ..... 51 Figure 9.4

63

which is the same as the source voltage for the 8052. Thus, there is no need of dual power

supplies.

Pin Configuration of MAX232

USB to RS232 Cable

Page 76: TRRIIBBHHU UV VAANN TUNNIIVEERRSSIITYY …...Figure 9.2 Simulation of Serial Communication Circuit in Proteus..... 50 Figure 9.3 A Frame Showing the Road Traffic ..... 51 Figure 9.4

64

Appendix D

Pin Diagram of ULN2803A

Page 77: TRRIIBBHHU UV VAANN TUNNIIVEERRSSIITYY …...Figure 9.2 Simulation of Serial Communication Circuit in Proteus..... 50 Figure 9.3 A Frame Showing the Road Traffic ..... 51 Figure 9.4

65

Appendix E

OpenCV (Open Source Computer Vision Library) is a library of programming functions

mainly aimed at real-time computer vision, developed by Intel, and now supported by

Willow Garage and Itseez. It is free for use under the open source BSD license. The library

is cross-platform. It focuses mainly on real-time image processing. If the library finds

Intel's Integrated Performance Primitives on the system, it will use these proprietary

optimized routines to accelerate itself.

OpenCV's application areas include:

i. 2D and 3D feature toolkits

ii. Egomotion estimation

iii. Facial recognition system

iv. Gesture recognition

v. Human–computer interaction (HCI)

vi. Mobile robotics

vii. Motion understanding

viii. Object identification

ix. Segmentation and Recognition

x. Stereopsis Stereo vision: depth perception from 2 cameras

xi. Structure from motion (SFM)

xii. Motion tracking

The library was originally written in C and this C interface makes OpenCV portable to

some specific platforms such as digital signal processors. Wrappers for languages such as

C#, Ch, Python, Ruby and Java (using JavaCV) have been developed to encourage

adoption by a wider audience.

However, since version 2.0, OpenCV includes both its traditional C interface as well as a

new C++ interface. This new interface seeks to reduce the number of lines of code

necessary to code up vision functionality as well as reduce common programming errors

such as memory leaks (through automatic data allocation and deallocation) that can arise

when using OpenCV in C. Most of the new developments and algorithms in OpenCV are

Page 78: TRRIIBBHHU UV VAANN TUNNIIVEERRSSIITYY …...Figure 9.2 Simulation of Serial Communication Circuit in Proteus..... 50 Figure 9.3 A Frame Showing the Road Traffic ..... 51 Figure 9.4

66

now developed in the C++ interface. Unfortunately, it is much more difficult to provide

wrappers in other languages to C++ code as opposed to C code; therefore the other

language wrappers are generally lacking some of the newer OpenCV 2.0 features. A

CUDA-based GPU interface has been in progress since September 2010.

OpenCV runs on Windows, Android, Maemo, FreeBSD, OpenBSD, iOS, Linux and Mac

OS. The user can get official releases from SourceForge, or take the current snapshot under

SVN from there. OpenCV uses CMake.

Courtesy: “OpenCV” http://en.wikipedia.org/wiki/OpenCV, 2012; “OpenCV”

http://opencv.willowgarage.com/wiki/

Page 79: TRRIIBBHHU UV VAANN TUNNIIVEERRSSIITYY …...Figure 9.2 Simulation of Serial Communication Circuit in Proteus..... 50 Figure 9.3 A Frame Showing the Road Traffic ..... 51 Figure 9.4

67

Appendix F

Qt Creator is a cross platform C++ IDE of QtSDK. It includes a visual debugger and an

integrated GUI layout and forms designer. The editor's features include syntax highlighting

and code auto completion. Qt Creator can be used for making GUI application with the use

of known programming language that is C++.

Qt Supports external library such as QExtSerial Port for reading and writing data from

Serial Ports. Qt also support Open CV library which has been used for DIP applications.

Also it supports QWT library for plotting and animation purposes. Qt has rich sets of in-

built library for GUI application.

Main Reasons to choose QT Creator:

i. It is well documented

ii. It runs in Windows and Linux

iii. It supports Open CV library.

iv. Its online help is available in QT Forums.

Qt allows execution of SQL language. Qt Creator has rich sets of virtual functions and

derived classes which is the core part of object oriented programming.

The main feature that makes Qt Creator different from other IDE such as Microsoft Visual

Studio is that it works on Signal and Slot mechanism. Signals and slots are used for

communication between objects. The signal and slot mechanism is central feature of Qt

Creator. Signal is emitted when particular event occurs and slot is the public or private

function. Hence, objects communicate with each other and functions with signal and slot

mechanism.

Courtesy: “Qt Creator” http://en.wikipedia.org/wiki/Qt_Creator, 2012; “Qt Creator”

http://qt.digia.com/product/developer-tools/, 2012

Page 80: TRRIIBBHHU UV VAANN TUNNIIVEERRSSIITYY …...Figure 9.2 Simulation of Serial Communication Circuit in Proteus..... 50 Figure 9.3 A Frame Showing the Road Traffic ..... 51 Figure 9.4

68

Appendix F

Control Interface Circuit

Traffic Lights Circuit

Page 81: TRRIIBBHHU UV VAANN TUNNIIVEERRSSIITYY …...Figure 9.2 Simulation of Serial Communication Circuit in Proteus..... 50 Figure 9.3 A Frame Showing the Road Traffic ..... 51 Figure 9.4

69

Appendix G

Contents of CD are as follows:

- Softcopy of the report of final year project

- Softcopy of the presentation of final year project

- Necessary datasheets of the ICs used in the hardware implementation

Page 82: TRRIIBBHHU UV VAANN TUNNIIVEERRSSIITYY …...Figure 9.2 Simulation of Serial Communication Circuit in Proteus..... 50 Figure 9.3 A Frame Showing the Road Traffic ..... 51 Figure 9.4

70