detecting speed of car

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 Kommentare

Walter Roberson
Walter Roberson am 17 Sep. 2013
I looked at the demo code and I do not see any speed involved in it.
nkumar
nkumar am 17 Sep. 2013
yes walter ,there is no spped calculation ,but i have to find the speed of the cars,kindly provide assistance

Melden Sie sich an, um zu kommentieren.

Antworten (2)

David Sanchez
David Sanchez am 17 Sep. 2013

0 Stimmen

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

1 Kommentar

nkumar
nkumar am 17 Sep. 2013
can you tell how we can calculate the length of road plz

Melden Sie sich an, um zu kommentieren.

Walter Roberson
Walter Roberson am 17 Sep. 2013

0 Stimmen

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 Kommentare

nkumar
nkumar am 17 Sep. 2013
In other reference http://www.mathworks.com/matlabcentral/answers/22194 image Analyst has told to use improfile,i have drawn two lines at starting and ending,how can we call improfile and calculate speed
Walter Roberson
Walter Roberson am 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
nkumar am 17 Sep. 2013
ok walter assumin i jave ahe attched image,can you tel how to call improfile plz
Walter Roberson
Walter Roberson am 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
nkumar am 17 Sep. 2013
ok Walter I is frame now in the code i have drawn two lines at starting and ending using the code
image_out(15:16,:,:) = 255;
image_out(110:111,:,:) = 255;
the image is at
now for this can u tell how to use improfile please
i have taken this from demo and modified a liitle bit
Walter Roberson
Walter Roberson am 17 Sep. 2013
Bearbeitet: Walter Roberson am 17 Sep. 2013
wid = size(image_out, 2);
c1 = improfile(image_out, [17 17], [1 wid])
c2 = improfile(image_out, [109 109], [1 wid])
nkumar
nkumar am 18 Sep. 2013
Bearbeitet: nkumar am 18 Sep. 2013
Walter i tried it and added all vales in c1 and c2 separately,but i get only Nan for all 120 frames in c1 and c2
Walter Roberson
Walter Roberson am 18 Sep. 2013
That particular case, of a horizontal profile, can be replaced by
c1 = image_out(17, :);
c2 = image_out(109, :);
nkumar
nkumar am 18 Sep. 2013
Thanks walter but one thing i noticed is that ,when taking first 15 frame the values are more or less same,wheter the vehicle crosses the line or not,so how we can determine the vehicle had crossed the line,on which aspect we have to determine it
nkumar
nkumar am 18 Sep. 2013
for each frame i am calculating improfile at a same point,but why i get different values,
Is it possible to do it in the following way
Suppose i have drawn a white line on the image and if i take mean of that line point i get values as 255
in next frame if vechile is o that line ,will the mean values be same or different,i tried but am getting same values only 255

Melden Sie sich an, um zu kommentieren.

Gefragt:

am 17 Sep. 2013

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by