how to calculate vehicle speed using mathematics and Image processing? i am doing my project in image processing.using segmentation i have detected the moving part(i.e the car) in the video successfully.

But now i want to calculate speed of vehicle.
in the above figure  i have added car positons at different time loaction captured in the video frames also its front view and side view.using frame rate i can calculate the time elapsed by vehicle to cover some distance. 

But i have one difficulty, as the vehicle goes away its size goes down also we can’t use linear scale to compute the distance 
For this can anybody help me for distance computation? i am have added the image so that u can get an idea about it..
thank u
Use the basis of the poles for calibration. They are at coordinates $$(X+kU, Y+kV, Z+kW)$$ for increasing $k$, where $(U, V, W)$ is the vector between two poles.

After perspective transformation, the projected coordinates are
$$(f\frac{X+kU}{Z+kW},f\frac{Y+kV}{Z+kW})=(\frac{x+ku}{1+kw}, \frac{y+kv}{1+kw}).$$
There are five unknowns, the coordinates of three points will be enough to find them.
The height of an object is more or less related inversely with the distance to the observer's eyes. At least, that is a calculation that looks nominally right in a raycaster game I wrote.