In metropolitan cities traffic jams are one of the major problems and for the common man and he who use to travel on their legs is one of the major problems. Many time it is seen the people are waiting at crossing to get the traffic clear and the people have to wait and keep standing for an hours to cross the road it become more complicated when any child and old women have to wait for long time to cross the road so today we are going to make smart computer vision based smart traffic light that checks how many people are waiting at zebra crossing and from how long they are waiting at zebra crossing and give priority to people rather than vehicles accordingly.
How Our System Works ?
So let’s start our project with some of required components
Bill of material
Assuming that you have already Raspbian os installed and with Python3 environment on raspberry pi and also have access to its desktop.
sudo apt-get update
sudo nano /etc/dphys-swapfile
Then change the line CONF_SWAPSIZE=100 to CONF_SWAPSIZE=1024
sudo /etc/init.d/dphys-swapfile stop
sudo /etc/init.d/dphys-swapfile start
After the installation you can now proceed with the cloning of TF modules, examples, and files using the following command:
git clone https://github.com/tensorflow/tensorflow.git
After successfully cloning, go to the directory → research folder → and paste the code attached with the article. Now open the python3 IDE.Now let’s understand and change the code. First we have import the required modules in code and these modules are:
Next we will set the path for tensor flow detection modules and the we will set the name and path for labels here we have using the “trafficlight.pbtxt”. Next part of code will check the camera video and cut it in various frames and after that we have code that will try to detect the objects in each frame and then map with the labels that is assigned in traffic.pbtxt . here in traffic.pbtxt have only two labels that is “person” and “bicycle”( you can exclude the bicycle )
Now in next part of the code we check the label of object detected and here we have set a substring ie “person” we use this substring to count the number of people in image.
Now we have created several if() conditional statement that checks weather number of people detected is greater than 0 . Next if () statement will check count number is greater than 3 if yes then it turns the redlight on to stop vehicles and let the people pass . if number of people waiting at crossing is less than 3 then it start counting the time and if the time exceeds the 60 min then it give priority to people and let them pass.
Now connect the RPI camera to RPI Camera port using ribbon cable and then connect the components as in diagram(Refer fig 8).
Now save the code and run the code in python3 IDE and wait for few minutes to load the TF modules and let the camera video window to appear and then bring the camera in front of many people if it detects the number of people detected is greater than 3 then it turn on red LED for stop sign. If people detected is less than 3 than wait for 60 second if the same people is wait for more than 60 seconds then it will let them pass and stop the vehicles by turning the red light on
This content was originally published here.