Wednesday 16 April 2014

Real Time Crowd Detection

Its not about IDEAS, its about making IDEAS happen. Just a couple of days earlier to the most not so awaited but significant annual final year project competition, Tantravihar'14, my group project was in a imperfectly non-working condition. Wherein I could still hear the professors who came for the scrutiny saying “Kay dakhavnar kay Tantra-vihar madhe?” (Which meant " what are you people gonna present in Tantra-vihar?"). And this unfortunate situation led us to move onto a Minimum-viable-model (as far as we called it that) with less hazards and fully planned functional project. So that we could at-least present a proper demo of our BIG idea and its workability. And the astonishing fact is we actually could procure Best project in Departmental category and also gained 2nd best project for the Inter-collegiate competition. For obvious reasons the attributes of which goes to the decisions we took at that point in time because " Failing to Plan is Planning to Fail" . This triumph of ours could be because we could choose a topic which was not only innovative but also practical and furnishing model of it , Prezi( Gaurav Ketkar) and our multi-domain outputs( Matlab, FPGA, Open CV i.e. Raspi) additionally the team's co-ordination was just perfect. 

 Coming on to our Big idea, whenever the final year project topics were to be selected, the University mandates us to look up for some real life issues faced by beings and get them solved by the use of technology. So we did a lot of brainstorming on this. So what is this one thing which connects each and every person in Mumbai or at-least most of them? It was Mumbai Local Trains. The Mumbai Suburban trains or Locals, as it is commonly known, is the life line of the city carry more than 7.2 million commuters out of the 13 million people residing in Mumbai , every single day, which is certainly more than the total population of Israel. 

Every day in Mumbai more than 200 trains make more than 2000 trips along 400 km of tracks carrying more passengers per kilometer than any railway on earth. Mumbai trains were built to hold 1700 passengers, but they often carry three times that number, leading to such a notorious crowding that railways have given peak hours a special name: The Super Dense Crush Load ( with 16 to 14 people per sq meter). During rush hours (its hours here, not hour), around 500 people stuff themselves into train cars meant only for 188. That's more than double the recommended figure. 

With some more observation, since our 4 years of travelling to college, we discovered that this crowding was particularly limited or more frequently seen in some bogies i.e. train cars which were either near to the Foot over bridge or near to the exits of some stations while some of the bogies still remained relatively less crowded.

EUREKA !!!

What if the information about such less crowded bogies be given to the people standing at the next station in advance?

So the people not only know which train to wait for but also know where to wait in order to get to their respective destination with a comfortable journey. So this was our BIG idea to make the journey of rail commuters better. As work as name, we named our project “G-Yantra" where G- stands for Gantavya meaning destination in Sanskrit and Yantra means Machine. Thus our project helps people reach their destinations in a better way than present. The technology which we are using to tackle this issue is “EDGE DETECTION"

So what is Edge detection?



Basically, this is what an edge detected image looks like. Whenever there is an abrupt change in the intensity level of the individual pixel an Edge is detected.

What makes this edge thing so useful?
We came up with a basic assumption (may be right or may be not) that More the number of people in the bogie more will be the number of edges. Sounds promising, isn't it?

Why did we choose edge detection? Are there any other methods?
Answer to the above question is yes, there are numerous methods, e.g. determining the approximate weight of bogie with a sensor and comparing it with the weight of an empty bogie. But the real issue with this is when we talk about fewer crowds or more crowds, we talk about the amount of space (volume) they occupy. Hence the calculation tends to go as not expected with the weight thing. On the other hand, edge detection works on a spatial area, proves more efficient here. Additionally, it is the simplest of algorithms and requires less computation comparatively.

The project on whole is as shown below:


Data input block is basically a Raspberry-Pi compatible camera which captures an image and sends this to the host(main controller) which in our case is the Raspberry-Pi. The image is then converted to grey-scale image in order to save the computation time and space (memory). This image is then sent to a FPGA (Field Programmable Gate Array).

Wait what?

Yes, FPGA. It is basically an array of gates which can be programmed to behave as an ASIC (Application Specific Integrated Chip). So FPGA(Math Processor in the fig.) does a dedicated task that to fast…. Faster

So how much faster?

Normally any software tool like MATLAB can also detect edges. But the time taken by it to process one image is 1.5 seconds. Seems fast, eh? But at the implementation level considering 4 cameras per bogie, there will be 48-50 images per train? So on the whole the processing time goes to 75 seconds. Besides FPGA can do the same thing i.e. 50 images in just 300 milliseconds.

Why do we need so much speed?

On an average, the minimum time between two closest stations in Mumbai railways is around 2-2.5 min. And in order for people to arrange themselves, we need to inform them at least 1.5-2 min prior to the arrival of train. That’s where the speed comes to be a heroic saviour.

So, FPGA processes the image faster and converts it into an edge detected image. The no. of white pixels is counted using a counter. Thus more edges more are the White pixels. This white pixel count is sent to the host computer again along with the Train-tag and the Bogie-tag.

What is Train-tag and Bogie-tag?

The system consists of numerous cameras on single train so identifying each photo's location and sending data to respective indicator is necessity of the project. Hence we incorporate a Train-tag and Bogie-tag in the last two pixels of the image itself. As the algorithm which we are using does not modify the corner pixels and also it does not affect the results, we overwrite the end pixels with Train-tag and Bogie-tag. Moreover this also reduces the additional overheads of writing it to meta-data of the photo.

Now, the Host computer (Raspi) receives the data. We have equipped the raspi with a look up table. Depending on the value of pixel count there are 5 levels of GARDI (Gardi means Crowd in Marathi). Thus there are different GARDI LEVELS (this is an official term coined by our group) depending on the no. of white pixels. This data is then sent using wireless media to the Micro-controller on the Next Platform.The Controller in our case is an Arduino UNO.

The Controller receives a 6 byte information. first 4 bytes of it is the Train-tag, which is used to identify the train and to which platform it will arrive.fifth byte is the Bogie-tag
helps identify the indicator, corresponding to the bogie, to be selected. The last byte is GARDI LEVEL. so according to the GARDI LEVEL the respective LEDs on the indicator are glowed.

Thus more the LEDs (especially the Red ones) are ON, more is the Crowd level. This data will surely help the boarding passengers on the next platform to arrange themselves in a better way. Thus moving from CHAOS to ORGANIZED CHAOS.

Here is the G-Yantra Team:



For Video Demonstration : https://www.youtube.com/watch?v=OhHBAHIgrec&index=3&list=PLonJJ3BVjZW7ilFOMjGZcnrcNXgusSl5l