Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

OpenCv calculate or convert the speed of a moving Object

I would like to get the real speed of a moving object from my camera or webCam

I used OpenCv **BackgroundSubtractorMOG2** then it return me the Foreground image( the moving object) then I draw two line for eg:

    line( resize_blur_Img, Point(10,0),Point(10,60), Scalar( 255, 0, 10 ),2, 8 );
 line( resize_blur_Img, Point(100,60),Point(100,0), Scalar( 0, 0, 0 ),2, 8 );

as you can see I can find the distance between the two line by a simple way can be ==> 90

and every time we the Object cross my line i save the time in this way

 time_t now = time(0);
  dt = ctime(&now);

dt will return the current time is second for eg dt return to me 1489755120 wich is the result from timeCrossedForLine 2 - timeCrossedForLine2

the when I use a simple formula to get the speed -->> Speed= Distance/Time

Applying to my situation I will get Speed=(90/1489755120)= 6.041261

-->> My Question is this 6.041261 will be in Km/h ?? or in m/s or other else

if i did not well calculate the speed could you please show the the other way???

Please I need you guy!!!!!