Abs
Abs

Reputation: 1766

How to get the ray equation of a 2d point in world space

I'm looking to get the world space ray equation of an (x, y) point in 2D space. So given (x, y), id like to get something like:

(x, y, z) = (x0, y0, z0) + t*(a, b, c)

where (x0, y0, z0) and (a, b, c) are vectors which I know.

I'm using the solvePnP function in OpenCV to turn a 3D model into 2D coordinates, so I have the rotation vector, transition vector, camera matrix and distortion coefficients. Can someone please explain the math necessary to get this ray equation in world space?

Upvotes: 0

Views: 2416

Answers (1)

Catree
Catree

Reputation: 2517

Here what I would do.

For a 2D image point in [u, v] coordinate, undistort the 2D coordinate and apply the reverse perspective transformation. OpenCV has already a function undistortPoints() that do that.

You will obtain a 3D coordinate in the normalized camera frame, that means at z=1.

For the line / ray equation, you have a starting point at (x0=0, y0=0, z0=0) and another point at (x, y, z=1).


Note about the reverse perspective transformation.

For a given camera matrix: camera matrix

The reverse perspective transformation is just: reverse perspective transformation


Note about frame coordinate transformation:

For a given world (or object) 3D point: world 3D coordinate

If you know the camera pose (using for example solvePnP()), you have the transformation matrix cTw:

cTw 2

To compute the 3D coordinate in the camera frame:

transformation

Upvotes: 3

Related Questions