detecting speed of car
Show older comments
I got some codes for tracking a car from
in this i have to find the speed of car,i dont have any idea on this ,kindly can anyone tell how to start finding spped of the car
2 Comments
Walter Roberson
on 17 Sep 2013
I looked at the demo code and I do not see any speed involved in it.
nkumar
on 17 Sep 2013
Answers (2)
David Sanchez
on 17 Sep 2013
You have to know the length of the road, then, measure the time taken by the car to go along that stretch of road.
velocity = length/time
Walter Roberson
on 17 Sep 2013
0 votes
Go there and use a tape measure, or lay down a long piece of string and later measure the length of the string, or use an ultrasonic range finder, or use a surveyor's transit. Or zoom in on it in Google Maps and tell that program to tell you the distance.
If you need to be able to do this for arbitrary scenes, then do you know the camera lens and specifications? With that you could calculate depth of field, and then do a fitting of the crispness on the image in order to estimate the corresponding pixel distance in the image; as you would then be able to calculate pixel to real-world correspondence, you could measure the pixel length of the road, and use the calculated correspondence to calculate the real-world road length.
If you need to work with arbitrary scenes without lens information, then you will need to go through several images until you can find a car or truck shown whose real-world length you can look up in the manufacturer's specifications. Real world information plus pixel distance allows you to calculate the ratio of pixel to real world, and then to measure the pixel length of the road and convert that to real-world distance.
But still the demo has absolutely no reference to speed, so it is not clear why you would care. The demo is only for counting cars.
11 Comments
nkumar
on 17 Sep 2013
Walter Roberson
on 17 Sep 2013
If you call improfile() on a particular set of points when there is no car across those points, then the returned values will have one set of intensities. If you later call improfile() on the same set of points but there is now a car across that line, then the returned values will have very different characteristics (darker for a dark car, possibly brighter for a bright car -- either way, significantly different). So for the frames with no cars across the line, the sum of squares of differences between those pixels between one frame and the next would be small when the frame has the same state (car or no car) as the previous frame, and the sum-of-squares would be much larger when the frame is changing state (car entering or car finishing)
nkumar
on 17 Sep 2013
nkumar
on 17 Sep 2013
Walter Roberson
on 17 Sep 2013
c = improfile(I,xi,yi,n)
where I is your image matrix (extracted from the video), and xi and yi are the pixel locations of the beginning and end of the line to be profiled, and n is the number of points along the line for which the profile would be taken.
Now all you need to do is figure out which line you want to measure across. For example if you want to trigger at the white line in the sample, then you could locate the white line and then profile the line one pixel further down (because the white line is clearly on top of the image obscuring the image.) You could use use the data cursor to figure out the positions you want, or you could use some other automated method. You could use one line for each lane if you want to count them individually: that might make it easier for the case in which two cars cross the white line at the same time.
nkumar
on 17 Sep 2013
Walter Roberson
on 17 Sep 2013
Edited: Walter Roberson
on 17 Sep 2013
wid = size(image_out, 2);
c1 = improfile(image_out, [17 17], [1 wid])
c2 = improfile(image_out, [109 109], [1 wid])
Walter Roberson
on 18 Sep 2013
That particular case, of a horizontal profile, can be replaced by
c1 = image_out(17, :);
c2 = image_out(109, :);
nkumar
on 18 Sep 2013
nkumar
on 18 Sep 2013
Categories
Find more on Image Category Classification in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!