Take the 2-minute tour ×
Mathematics Stack Exchange is a question and answer site for people studying math at any level and professionals in related fields. It's 100% free, no registration required.

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.

share|improve this question

2 Answers 2

up vote 0 down vote accepted

I'm not sure what you mean by “focal vector” in your computation. Is it supposed to be a vector within or orthogonal to the focal plane?

In order for that computation to make sense, you'll need q to be the direction vector, i.e. the unit vector of the direction in which the camera is pointed, orthogonal to the focal plane. You don't need any “up” direction for this. The dot product will be maximal (i.e. equal to |p| if p lies in the same direction as q, and will be zero if p is orthogonal to q, i.e. in the focal plane. The vector p should obviously be computed relative to the camera location.

For future reference, in case you or someone reading this might indeed need that “up” vector: you can compute that as follows:

x = -cos(yaw)*sin(pitch)
y = -sin(yaw)*sin(pitch)
z = cos(pitch)

You can think of this as follows: take the camera with pitch=0. Then “up” will be the z direction. When you change pitch, the z component will decrease, and the x and y components will increase. More specifically, when you increase pitch, then the x any y coordinates of the up vector will point away from the direction of your camera. Hence the minuses.

share|improve this answer
    
Thanks, you have answered my question, even thouhgh as you rightly point out I don't really need the "up" vector. Sorry for the confusing terminology. By "focal vector" I meant the vector in the direction the camera is pointed, i.e. the direction vector. Obviously I had confused my self sufficiently and was thinking it had to be the "up" vector, which wouldn't work. Thanks again. –  Michael Apr 30 '13 at 7:44

I was trying for the "up" vector to, you said

x = -cos(yaw)*sin(pitch) y = -sin(yaw)*sin(pitch) z = cos(pitch)

however, you forgot to include the roll variable, can you expand the equation to include that?

share|improve this answer
1  
This is really a comment, not an answer. It would be better to use the "add a comment" link to put this in the comment section directly below the question. By the way, OP apparently is using angle coordinates in which direction "forward" is independent of roll, so roll is not missing from the given equations, but it does need to be defined for the "up" vector. –  David K Aug 5 at 22:53

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.