I have a RGB image, and for each pixel in the image I also have its real world coordinate. I also have the location (real world coordinate) yaw, pitch and roll of the camera. I am trying to produce a depth map but my maths is letting me down.
Basically, I have a array points (world coordinate frame) and a camera location (also world coordinate frame) and yaw and pitch of camera. I want to find the distance of each point from the plane containing the camera (focal plane). From my searching, trying to understand pinhole camera model and coordinate frames I have managed to confuse my self.
Assuming the math below is correct, the distance I seek is just the dot product of the point and the up vector. But I can't seem to calculate the up vector (probably some thing simple).
The focal plane itself is likely not aligned with the x,y,z axes of the world. However, if we can calculate the direction into the scene (orthogonal to the plane) and the up vector (incident to the focal plane). We can compute the orthogonal distance to the point (from the focal plane) by noting that:
cos(t) = p.q/(|p||q|) where p is the position vector of the point of interest, q is the unit direction vector into the scene, p.q is the dot product, |p| is magnitude of p and t is the angle between the vectors p and q. But c/h = cos(t) where h = |p| and c is the orthogonal distance from the focal plane. Therefore: c = h*cos(t) c = h * p.q/(|p||q|) c = p.q/|q| (since h = |p|) c = p.q (since |q| = 1, recall q is unit focal vector)
Define pitch=0 as horizontal (z=0) and yaw as counter-clockwise from the x axis, then the direction vector will be:
x = cos(yaw)*cos(pitch) y = sin(yaw)*cos(pitch) z = sin(pitch)
Assuming the math is correct, how can I calculate the unit "up" vector orthogonal to the direction into the scene?
If the math is incorrect, how should I calculate this distance?
Is their an easier/better/more robust way than I am trying?
EDIT: Fixed some terminology based on solution provided below.