# Calculate the distance between two objects (example cars) in a video

Hello, I am using Haar cascade function to detect the cars from a video file and want to find the distance between two cars? Is it possible to do that using OpenCV or something similar to find the gap between two detected objects? Thanks

edit retag close merge delete

Sort by » oldest newest most voted

You must calibration camera(find extrinsic and intrinsic camera matrix, Use can using cheeboard or Calibrated Cameras in OpenGL width gluPerspective without glFrustum method).

After, set of 2D points provided onto 3D space. We do know many points on the 3D model ( i.e. (U, V, W) ), but we do not know (X, Y, Z). We only know the location of the 2D points ( i.e. (x, y) ). In the absence of radial distortion, the coordinates (x, y) of point p in the image coordinates is given by where, fx and fy are the focal lengths in the x and y directions, and (cx, cy) is the optical center (assume fx = fy = focal length). Things get slightly more complicated when radial distortion is involved and for the purpose of simplicity I am leaving it out. Using cv::solvePnP the function solvePnP and solvePnPRansac can be used to estimate pose.

Calculate distance and bearing between two point Or you can using double hypot method measure distance.

more

simran i am doing work on same thing can you help me please ,i done one source code which can detect object but i want also distance from camera to detecting things how much far.did you finished this program i am very new i think you understand #monxarat answer . help me please i dont know how i can use calibration method thanks

Official site

GitHub

Wiki

Documentation