# Formula to calculate the speed of moving vehicle using focal length in openCV

Hello, I am doing a project on Estimating the speed of moving vehicle from the video captured in openCV. Now I have computed the speed using – (Euclidean distance between two centroids)/ time. But I exactly want the actual speed of vehicle which’s calculated using the focal length of the camera. I want to know the formula for the same. I googled it but it’s of no use.

edit retag close merge delete

HELLO THERE, I M WORKING ON SAME PROJECT, CAN U PLS SHARE UR CODE TO FIND SPEED USING CENTROIDS

( 2017-02-21 04:12:44 -0500 )edit

Sort by » oldest newest most voted

In this image : f stands for focal length , q1,q2 distances of an object from the camera , y a dimension of the object and x1,x2 the real size of the object in an image.

Let Dq=q1-q2 : , where k is the size of the CCD of the camera , so Px1,Px2 are the pixel sizes in the image .

In that way , between two successive frames you can compute :

Dq and divide it by the time between two successive frames to find the velocity .

Basic assumption is that the camera is centered in the middle of the car and that there are no turns etc. in the road .

more

This was what I exactly needed. Just perfect. Thank you so much :)

( 2016-03-25 11:30:21 -0500 )edit

Glad i helped ! :) Hope i will get voted up

( 2016-03-26 07:46:17 -0500 )edit

I didnt get what exactly is 'y' in the above figure. And most importantly how can we calculate the real height of the object? And what is x1 and x2 in the above figure? I lately read the basic assumption you have mentioned, but here in our project we are using a static camera to capture the video. I would be glad if you answer my above doubts.

( 2016-03-28 09:20:00 -0500 )edit

Y is for example the height of an object in real life . You have to have one unknown parameter . So you have to suppose the height of the object as known, e.g. of a traffic signs 40 cm radius or of a tree 5m height. Then x1,x2 are the dimensions of the tree for example in two images , if you open it via paint for example you can see how many pixel each object takes . It is logical that the size of the objects in pixels grow as the camera approaches the real object .

( 2016-03-31 10:20:40 -0500 )edit

We are using a stationery camera. So does this formula work for the same?

( 2016-04-05 09:47:25 -0500 )edit

Yes it is the same , but now the object is approaching the camera not the opposite .

( 2016-04-05 10:44:45 -0500 )edit

CAN U PLEASE SHARE THE PYTHON CODE FOR SPEED MEASUREMENT BY CENTROID METHOD??

( 2017-02-21 04:14:37 -0500 )edit

Official site

GitHub

Wiki

Documentation