Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Find speed of vehicle from images

I am doing a project to find the speed of a vehicle from images. We are taking these images from within the vehicle. We will be marking some object from the 1st image as a reference. Using the properties of the same object in the next image, we must calculate the speed of the moving vehicle. Can anyone help me here??? I am using python opencv. I have succeeded till finding the marked pixel in the 2nd image using Optical flow method. Can anyone help me with the rest?

like image 553
Rony Varghese Avatar asked Feb 02 '11 09:02

Rony Varghese


1 Answers

Knowing the acquisition frequency, you must now find the distance between the successive positions of the marker.

To find this distance, I suggest you estimate the pose of the marker for each image. Loosely speaking, the "pose" is the transformation matrix expressing the coordinates of an object relative to a camera. Once you have those successive coordinates, you can compute the distance, and then the speed.

Pose estimation is the process of computing the position and orientation of a known 3D object relative to a 2D camera. The resulting pose is the transformation matrix describing the object's referential in the camera's referential.

Pose description

OpenCV implements a pose estimation algorithm: Posit. The doc says:

Given some 3D points (in object coordinate system) of the object, at least four non-coplanar points, their corresponding 2D projections in the image, and the focal length of the camera, the algorithm is able to estimate the object's pose.

This means:

  1. You must know the focal length of your camera
  2. You must know the geometry of your marker
  3. You must be able to match four know points of your marker in the 2D image

You may have to compute the focal length of the camera using the calibration routines provided by OpenCV. I think you have the two other required data.

Edit:

// Algorithm example

MarkerCoords = {Four coordinates of know 3D points}

I1 = take 1st image
F1 = focal(I1)
MarkerPixels1 = {Matching pixels in I1}
Pose1 = posit(MarkerCoords, MarkerPixels1, F1)

I2 = take 2nd image
F2 = focal(I2)
MarkerPixels2 = {Matching pixels in I2 by optical flow}
Pose2 = posit(MarkerCoords, MarkerPixels2, F2)

o1 = origin_of_camera * Pose1 // Origin of camera is
o2 = origin_of_camera * Pose2 // typically [0,0,0]
dist = euclidean_distance(o1, o2)
speed = dist/frequency

Edit 2: (Answers to comments)

"What is the acquisition frequency?"

Computing the speed of your vehicle is equivalent to computing the speed of the marker. (In the first case, the referential is the marker attached to the earth, in the second case, the referential is the camera attached to the vehicle.) This is expressed by the following equation:

speed = D/(t2-t1)

With:

  • D the distance [o1 o2]
  • o1 the position of the marker at time t1
  • o2 the position of the marker at time t2

You can retrieve the elapsed time either by extracting t1 and t2 from the metadata of your photos, or from the acquisition frequency of your imaging device: t2-t1 = T = 1/F.

"Won't it be better to mark simple things like posters? And if doing so can't we consider it as a 2d object?"

This is not possible with the Posit algorithm (or with any other pose estimation algorithm as far as I know): it requires four non-coplanar points. This means you cannot chose a 2D object embedded in a 3D space, you have to chose an object with some depth.

On the other hand, you can use a really simple shape, as far as it is a volume. (A cube for example.)

like image 102
Julien-L Avatar answered Sep 29 '22 20:09

Julien-L