views:

126

answers:

2

I have a camera mounted on a tripod its motion is restricted to pan and tilt rotation. It is looking at dot that is at a known location directly in front of the camera. If the camera looks at the dot and gets the 2d coordinate of it, is it possible to deduce the camera's rotation so that I can overlay some 3d models properly aligned to the scene.

I was thinking that it could be solved by reversing the formula that you would use to plot the 2d point you could derive a formula to take a 2d point and give back the camera rotation.

I am thinking that the 2d plot would be something like Dot's 3d Target World Position * Camera Position Matrix * Camera Rotation Matrix * Perspective Matrix = 2d point

Is it possible to derive the camera's rotation from the 2d point given that the camera and dot's position are known as well as the perspective matrix (I am assuming I should be able to guess at this and get close by tweaking the field of vision value)?

A: 

If your camera renders an image that is w pixels wide by h pixels high, then you can determine the delta distance (in pixels, dw and dh) from where the dot is to where it should be. Since you are assuming to know the viewing angle, you can determine the actual length (in real-world dimensions) of a pixel. The resulting conversion from dw and dh into real-world distances would give you (e.g.) x and y, respectively.

You know z, the distance from the camera to the dot.

In order to get the two angles in question, consider two different trigonometry problems, with the given lengths of two sides of a right triangle (z and x, for example). If it helps, draw out a top-view of the problem in two dimensions to get the pan angle. Repeat for the tilt angle, using a side-view drawing.

TreDubZedd
i am unclear about the delta between where the dot versus where it should be. How do I know where it SHOULD be?
Mr Bell
If the camera is aimed directly at the dot, the dot will appear in the center of the resulting 2D image (Width/2, Height/2).
TreDubZedd
Ok, i think i getcha. i think i understand it, and it makes sense if the camera is rotating about its own center, but it won't work if the camera is translated off the center of rotation, will it?
Mr Bell
@Mr Bell: translation will not be covered. But the question reads "its motion is restricted to pan and tilt rotation"... that covers it, no?
xtofl
Rotation is the only variable. However, translation of the camera relative its point of rotation must be accounted for since in practicality the camera won't be rotating around the exact center of the lens. In fact read my comment to Beta about how the camera will actually be set up
Mr Bell
Is the length of the "telescope" known? If so, I assume you know the distance from the dot to the center of rotation. Use that length and solve the problem as before (when the camera was the center of rotation).
TreDubZedd
+1  A: 
Beta
by pan and tilt I mean the camera can pan horizontally (rotate about a Y axis) and tilt up and down (rotate about a X axis). Rotation about the z axis is locked so "up" is known. I am unclear about how to go backwards from the 3d to 2d matrix because i believe the camera must be translated then rotated and then onto the perspective matrix. So working backwards I could see how you could get from the 2d point to the 3d point pre perspective, but since the translation occures before the rotation how do you account for it?
Mr Bell
Are the axes you refer to fixed in the body of the camera? And why should translation be necessary when nothing is undergoing translational motion? And by "perspective matrix" do you mean the transformation from 3D (in the camera coordinate frame) to 2D?
Beta
Imagine a web cam fixed to the end of a telescope mounted on a tripod. The telescope is panning and tilting on the tripod, the camera is rotating (panning and tilting) around the point that the telescope body is attached to the tripod. In matrix terms the camera's position is translated away from the tripod mount and then rotatedYou are correct about the perspective matrix. I am referring to the matrix you apply to get perspective foreshortening and move into 2d space
Mr Bell