Ask Your Question

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

asked 2018-09-17 00:42:29 -0500

Simran gravatar image

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 flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted

answered 2018-09-18 04:31:53 -0500

monxarat gravatar image

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

image description

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.

image description

See more

Using cv::solvePnP the function solvePnP and solvePnPRansac can be used to estimate pose.

Calculate distance and bearing between two point

image description

Or you can using double hypot method measure distance.

edit flag offensive delete link more


Thank you so much!

Simran gravatar imageSimran ( 2018-10-09 16:25:16 -0500 )edit

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

Ayeshayounis gravatar imageAyeshayounis ( 2019-09-12 01:50:48 -0500 )edit

Question Tools

1 follower


Asked: 2018-09-17 00:42:29 -0500

Seen: 1,235 times

Last updated: Sep 18 '18