Simian
Posts: 3
Joined: Thu Jun 06, 2013 8:42 pm

Ideas sought for counting vehicles...

Thu Jun 06, 2013 9:29 pm

We have a major rush hour traffic problem where I live and we have some theories about the causes but we need to understand where vehicles are coming from and going to at a specific complex junction (6 roads meet there) during a 2hr period in order to test our hypothesis, and provide evidence. I think we need to monitor all traffic simultaneously to really understand the flows.

As a village group we can't afford to get consultants so I thought I'd try to set up a counting system on specific roads and maybe use a Pi and sensors to collect data. I'm trying to work out the best way to do this cost effectively. I'm thinking possibly PIR or ultrasonic sensors at the roadside registering a pulse every time a vehicle passes, connected to Pi by Bluetooth/WiFi.
Any ideas greatly appreciated! :)

BillStephenson
Posts: 254
Joined: Thu May 17, 2012 1:25 am
Location: SW Missouri Ozarks
Contact: Website

Re: Ideas sought for counting vehicles...

Fri Jun 07, 2013 2:17 am

I've done some work on "ITS" (Intelligent Traffic Systems). We used sensors made by 3M corporation to count cars but I'm sure they were very expensive.

Our local road department uses "Road Tubes", a rubber hose laid across the road that's connected to a counter. Here's one like it. Those can probably be connected to an RPi like you want to do.

I made a web based map that took that data and displayed the roads with Red,Yellow, or Green lines depending on how many cars were there. I used Perl and the GD graphics libraries to open a graphic map and draw the road lines on it and output it to a web browser, and the LWP perl libraries to communicate with a main server that was collecting the data. A cronjob fired a perl script at defined intervals to retrieve the data from the server.

Perl, GD, and LWP, are all on the stock Raspbian OS. You can use C code with GD, but I installed the GD.pm perl module to create the map graphic with perl. I've tested that on Raspbian and it worked great.

User avatar
liudr
Posts: 687
Joined: Sat Jun 01, 2013 12:11 am
Location: Central MN, USA
Contact: Website

Re: Ideas sought for counting vehicles...

Fri Jun 07, 2013 2:19 am

I think both PIR and sonic rangers are out of the question. In an outdoor and noisy environment PIR gets flooded by the sun (it is personnel sensor anyway, not for objects), and sonic rangers get overloaded by the traffic noise. If you can't afford to dig holes on the ground and bury induction sensors, you may have to hire junior consultants, i.e. children with hand counters and count traffic. But, you can give then a pi each so the count is correlated to exact time. Set up a poll so each child will only count the vehicle if it passes the poll. Since it's traffic jam, speeds and slow and hopefully side streets are safe. Another way I am thinking is to simultaneously record the traffic of the 6 junctions and later hire children to count in a safe home environment. They can even relate the heading of each car :)
Arduino data loggers, user interface, printed circuit board designer since 2009, RPI 3B 2B 2B Zero Jessie, assembly/C/C++/java/python programmer since the 80's

PiGraham
Posts: 3929
Joined: Fri Jun 07, 2013 12:37 pm
Location: Waterlooville

Re: Ideas sought for counting vehicles...

Fri Jun 07, 2013 1:13 pm

One way to do this is to ID vehicles at each point. You get best accuracy counts and routes this way because you know where every car comes from and goes to.
ANPR has been implemented on a Pi. See here:
http://www.singaporegateway.com/optasia/imps.html
That's commercial ("under $500") so it probably doesn't suit this application, but you could approach them to see if they would provide software for a community project / beta test site for free.

Another way to do this is optical flow, if you can position a Pi high enough to look down at the junction. OpenCV will run on the Pi and can track motion in video streams.

You could hook up some through-beam sensors across the roads and correlate the signals to estimate traffic flow. I was impressed with these very cheap sensors: http://www.amazon.co.uk/gp/product/B00A ... UTF8&psc=1
Spec'ed at 15m range they might work across single carriageways if you put sunshields (e.g. black drainpipe) over them.

If you use them in pairs with a small separation you can tell, in most cases, which direction a vehicle breaking the beams is travelling. The two outputs provide a grey code - 00, 01, 11, 10.
Only one bit changes at any time and you can tell which direction the edge causing the transition is moving.

Obviously sensing across single carriageway roads will miss some vehicles if there is stationary or opposite flow traffic blocking the sensor when another vehicle passes.

You may be able to make use of cheap radar doppler sensors like these:
http://www.ebay.com/bhp/doppler-sensor.
The possibility of measuring vehicle speed may be an added bonus.

Good luck!

Simian
Posts: 3
Joined: Thu Jun 06, 2013 8:42 pm

Re: Ideas sought for counting vehicles...

Sun Jun 09, 2013 5:11 pm

Thanks guys! Some really good ideas there! I really like the idea of being able to track the route taken by vehicles, if I can get my head round it. I spent an hour on Friday doing an eyeball estimate of most frequently used paths through the junctions and found a few surprises - We'd assumed that most vehicles from A were going to B, where it semms that in actual fact they are going to C and D - and that's just one of the incoming paths, so lots of work to do. I think I may have to see if the Highways department can help. It's a major traffic problem but it doesn't seem anyone has any useful data!
One really simple thing I noticed while watching the junctions was that every vehicle had to pull right up to the line before they could see traffic approaching from the right of way side - and hence they had to stop, look and then start again. If we just cut back the undergrowth around the junction a little that in itself will have a small but noticeable effect, as reaction times to gaps in right of way traffic would be better exploited.
Anyway, I'm going to try out some if not all of the ideas above. I'll let you know how it goes. Got various sensors in the mail....

folkentx
Posts: 2
Joined: Wed Jun 12, 2013 8:33 pm

Re: Ideas sought for counting vehicles...

Thu Jun 13, 2013 1:18 am

I want to do the same thing. I'm doing a uni project, and I need counting vehicles and categorize them. I'm in the "thinking how to do it" process, I started today. Of what I found out and reading the responces, I think the best way is using open cv and the camera board for the pi. But I don't know if it is technicaly possible (I'm a new user of the pi and opencv). Any ideas if it is possible?

Heres some videos of opencv counter in action:

http://www.youtube.com/watch?v=2zFudElDmYk

http://www.youtube.com/watch?v=uYPIrsqN7K8

I'll be waiting for any update and obviously I'll update any progress to.

(I speak spanish, so if you notice any gramma errors, sorry about that)

folkentx
Posts: 2
Joined: Wed Jun 12, 2013 8:33 pm

Re: Ideas sought for counting vehicles...

Thu Jun 13, 2013 1:31 am

I also found this post here that may help:

http://www.raspberrypi.org/phpBB3/viewt ... cv#p368684

Grumpy_Git
Posts: 12
Joined: Tue Mar 06, 2012 11:30 am

Re: Ideas sought for counting vehicles...

Thu Jun 13, 2013 9:06 am

Simian

I would be hesitant to suggest that you put any hardware on the street, especially that has some kind of active output, you leave yourself liable to litigation for any incidents that may occur (solicitors will try everything to divert blame for RTAs)

I would suggest that if you have a highways issue you pursue the local highway authority more vigourously, they have an obligation to look into this kind of thing, and under FOI they would have to provide any information you request that is on file (such as surveys etc..) as well as respond within a reasonable time period.

If you could arrange a site visit with a council representative you would probably find they would spot the issues without surveys, they are trained in this after all.

Would you care to provide any more info on the actual traffic problem/the junction in question, as a Traffic Engineer I would be interested to know more.

Simian
Posts: 3
Joined: Thu Jun 06, 2013 8:42 pm

Re: Ideas sought for counting vehicles...

Thu Jun 13, 2013 3:25 pm

Thanks G-G...

Yes, on reflection I agree I could end up in all kinds of hassle. My problem is this seems to be a Catch22 type problem. I can't get the Highways Dept attention unless I have evidence.... I think maybe we're back to having a few of us doing an eyeball survey, making sure we are well out of vehicle sightlines.

The main problem is that we have two predominant traffic streams - one going SE->NW and the other going NW->SW, and this interchange on the edge of our village is where the flows cross over. It's the A3/B3000 interchange since you ask. If you know the area you'll be aware that traffic has noticeably increased since the A3 Hindhead tunnel opened a year ago. There will be an official traffic survey in due course related to this change but I don't think we'll be included in the consideration. I need to get us on the agenda. Hence this self-help idea. Any other ideas always welcome!

mrteach
Posts: 181
Joined: Sun May 26, 2013 6:49 am

Re: Ideas sought for counting vehicles...

Fri Jun 14, 2013 9:49 pm

A method that shouldn't cause any problems to the traffic, but more difficult to crunch numbers is to set up pi cams on roof tops and just record. Save the data. Mesh it together. and make notes.
depending on the area size you could do a fully connected mesh so you have a birds eye view of the whole town, but that would require a lot of pis I would assume. Perhaps just park them in strategic locals after your prior analysis of observing.
It will take time. You could later also make some kind of program (or find one) that can identify the cars and such by looking at all your videos.

johnpa
Posts: 1
Joined: Mon Jul 15, 2013 6:59 pm

Re: Ideas sought for counting vehicles...

Mon Jul 15, 2013 7:18 pm

Hi Simian

I was very interested to read about your project.

I'm sorry to hear you feel your concerns will not be listened to by your local highways team. Perhaps email me at highways@surreycc.gov.uk and we will look into further?

John (Pateman)
Surrey Highways

User avatar
jbeale
Posts: 3649
Joined: Tue Nov 22, 2011 11:51 pm
Contact: Website

Re: Ideas sought for counting vehicles...

Mon Jul 15, 2013 9:58 pm

Long ago, I constructed a traffic monitor, using two separate IR beam-breaking systems, meaning four roadside posts (two TX, two RX). This was on a two-lane road in a residential neighborhood (actually, university graduate housing area). I used PVC pipe painted drab grey and over several months, no one noticed. It was interesting, I pointed directly at one post to my roommate and he still couldn't see it. I actually touched it and he said, "Oh, that's it? but that's just... a post?"

This was almost 20 years ago. I used a 8051 family microcontroller programmed in BASIC and assembly, to run it. The IR beam-break system may not work well for busy streets with more lanes, and of course requires a lot of hardware to be installed where it is vulnerable to various trouble.

see also: http://www.bealecorner.org/best/measure/car/cidx.html

Also... I heard secondhand that the university public safety dept. had some interest in the idea because they wanted to count bicycle traffic, and their pneumatic hoses designed for car counting would not register the small weight of a bicycle. They never contacted me directly though.

The slick, high-tech solution would certainly be a machine vision application tracking cars from some high vantage point. I suppose that has already been done... I suspect the RPi might not be the best platform to track traffic moving at speed, unless you could get the algorithm running on the GPU, or maybe just use the RPi camera as a webcam, and stream the video to another machine for processing.
Last edited by jbeale on Tue Jul 16, 2013 4:48 pm, edited 2 times in total.

User avatar
Burngate
Posts: 6290
Joined: Thu Sep 29, 2011 4:34 pm
Location: Berkshire UK Tralfamadore
Contact: Website

Re: Ideas sought for counting vehicles...

Tue Jul 16, 2013 8:46 am

Off Topic ...
jbeale wrote:"Oh, that's it? but that's just... a post?"
I don't know if it's true elsewhere, but here there seems to be a rule that blue pipes are for water, yellow for gas, green for telecoms ... Some time ago I saw at the side of the road, some workmen with some grey pipe and wondered what that was for. Turns out it was a post.

Return to “Automation, sensing and robotics”