Find speed of vehicle from images

半城伤御伤魂 提交于 2019-11-30 07:22:24

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.

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.)

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!