Sign in to follow this  
Followers 0
Matty

Video Analysis of Road Traffic

4 posts in this topic

Hey guys.

I am a doing a research project on motorways/highways and I need to analyse vehicles traveling on roads. I basically need to track when a vehicle passes over a point on a road. But I need to do this for two points per lane, often two or three lanes. This is a minimum requirement that I need a program to do. It would need to also have a timer output. I'll try to explain with an example...

I have video footage of a road with cars going down. I want to be able to work out the speed of cars travelling, the distance between each car, and the number of cars per hour.

The latter is easy to do. I just need to pick one point on a lane and count each car. So I would start a timer, press a button and it would note down the time. I have already written a program where I can manually do this...

So I press start and watch the video...A car goes over the point, I press a button. A time comes out... 00:05. Another car one second later, 00:06. Is it possible to have AutoIT do this automatically? I have and idea but it involves leaving a mouse cursor over the video and letting it run. This would of course take hours...

I hope I am making sense!

If anyone knows if its possible to achieve other tasks...Perhaps tracking an object on a video? Surely if you can track a moving object it could output things like speed, distance between cars etc.

Any help is appreciated!

Share this post


Link to post
Share on other sites



There might be people here with expertise in this but I'm not one of them. But it sounds easy. I would define a small rectangle or a line across a lane in one position and another some distance away, maybe less than the shortest vehicle away but otherwise as far as possible. Assuming you can halt the video you could press a key to calibrate line A or line B which is how the line looks with no vehicle. Make some allowance for small changes so the reference can slowly change because the lighting conditions will change.

Then when line 1 doesn't match the reference there is a car, when line 2 changes later to detect a car then you can work out the speed of the car. The number of cars is the number of transitions from no car to car etc., the distance between cars is the speed multiplied by the time from car-gone to car-arrived.

So that's tomorrow morning sorted out. What are you going to do in the afternoon?


Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.

Share this post


Link to post
Share on other sites

Thats pretty much the idea I had. What do you think the best functions are to use?

Is there a way I can have PixelGetColor to have some sort of tolerance? Or PixelCheckSum. There are some artifacts on the video so the colour of an individual pixel will be constantly changing. I'm going to be honest, my knowledge of programming is pretty limited...

My best thought is to combine an autoit script with my existing program. Basically my current program is a timer, and when I press a button, for example x. A file is generated with the the time and then x. So I could run an autoit script that has a pixel colour check function constantly scanning at a co-ordinate that I have picked and when the colour changes enough from the colour of the road it will simulate a key press.

So...

I start the autoit script. It asks how many points I want to monitor. I type 4. Two points on each lane of the road. It asks me to click on the video where these points are. I will click with the video paused so that I can click where the road is empty and no cars are present. It records the colour. Then I press a button or click on a start button it will continuously scan the points until a point changes. When a point changes colour, autoit will simulate a key press. 1 for point 1, 2 for point 2...etc.

Is this easy enough to do? I really need help writing this thing!

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

Thats pretty much the idea I had. What do you think the best functions are to use?

Is there a way I can have PixelGetColor to have some sort of tolerance? Or PixelCheckSum. There are some artifacts on the video so the colour of an individual pixel will be constantly changing. I'm going to be honest, my knowledge of programming is pretty limited...

My best thought is to combine an autoit script with my existing program. Basically my current program is a timer, and when I press a button, for example x. A file is generated with the the time and then x. So I could run an autoit script that has a pixel colour check function constantly scanning at a co-ordinate that I have picked and when the colour changes enough from the colour of the road it will simulate a key press.

So...

I start the autoit script. It asks how many points I want to monitor. I type 4. Two points on each lane of the road. It asks me to click on the video where these points are. I will click with the video paused so that I can click where the road is empty and no cars are present. It records the colour. Then I press a button or click on a start button it will continuously scan the points until a point changes. When a point changes colour, autoit will simulate a key press. 1 for point 1, 2 for point 2...etc.

Is this easy enough to do? I really need help writing this thing!

It's a bit much expecting me to know how to do what I suggest! :(

First you need to have more than one pixel for the reason you gave, it could change completely without any traffic at all. I have very little experience using the pixel functions, but I would try PixelGetColour for say 20 pixels from the point you click going across the lane and add all 20 values. Then say if the result is withing some tolerance of that it is the road, then make that the new reference, or make the average of the last 2 references the new reference say. I don't know how fast the pixel functions are so you will need to play with it a bit. I wouldn't use PixelChkSum because it would be difficult to allow for the gradual change in the reference which might occur throughout the day.

No need to make your script simulate a key press; just call a function which writes to your file. I don't think you should need any other program. But remember I don't know what I'm talking about.

EDIT. You had better check that the PixelGetColor works for a pixel in the video. If you take a screen shot of something playing in MPlayer you get a black rectangle. You can try with the WindowInfoTool that comes with AutoIt and use the mouse Tab to see the colour under the cursor.

Edited by martin

Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0