PDA

View Full Version : Camera Position Estimation...


Msesha
April 6th, 2005, 12:18 AM
Hi All,
The ARtoolkit arGetTransMat gives the transformation matrix.

arGetTransMat(&marker_info[0], patt_center, patt_width, Matrix);
Now, if I use this matrix's last column, I get the translation of the pattern with respect to the camera.

Now, in my case the camera moves and the pattern is fixed. So, I would like to get the position of the camera with respect to the pattern. E.g In case there is roll in the camera (but the camera does not move) the values of camera position should be pretty constant.

For this, I use ...
arUtilMatInv(Matrix, cam_trans);
arUtilMat2QuatPos( cam_trans, quat, pos );

The pos returned by this function is wildly fluctuating. So, how can I find the camera position with respect to the marker... Is there a way...

Thanks a ton. (Hopefully if I get these wrapped up I can send you guys a tutorial on this stuff that I m putting together)...
Sasha,

philip_lamb
April 6th, 2005, 04:07 AM
If you have the position of the marker with respect to the camera (say [px, py, pz] which you got from the last row of the matrix) then the position of the camera w.r.t. a fixed marker is just the inverse of that vector, i.e. [-px, -py, -pz] which is very easy!

It gets a bit more complicated if you want the orientation of the camera w.r.t. a fixed marker.. but not too much more difficult, because you can exploit the fact that the inverse of an orientation matrix (the 3 x 3 matrix at the upper left of a 4x4 homogenous coordinate transform matrix) is just its transpose.

Here is some C code to get the inverse HCT matrix:
float TransMat[12], T[16], T_inv[16];
arGetTransMat(&marker_info[0], patt_center, patt_width, TransMat)
arglCameraView(TransMat, T, 1.0);
T_inv[0] = T[ 0];
T_inv[1] = T[ 4];
T_inv[2] = T[ 8];
T_inv[3] = 0.0f;
T_inv[4] = T[ 1];
T_inv[5] = T[ 5];
T_inv[6] = T[ 9];
T_inv[7] = 0.0f;
T_inv[8] = T[ 2];
T_inv[9] = T[ 6];
T_inv[10] = T[10];
T_inv[11] = 0.0f;
T_inv[12] = -T[12];
T_inv[13] = -T[13];
T_inv[14] = -T[14];
T_inv[15] = 1.0f;

(The arglCameraView(TransMat, T, 1.0); step above just converts ARToolKit's 3x4 transform matrix into a standard 4x4 OpenGL transform matrix by adding a row [0 0 0 1] to the bottom.)

enjoy!
Phil.

Msesha
April 7th, 2005, 03:12 AM
Hi Philip,
Thanks a lot for the reply. In my case I do know that [-px, -py, -pz] is the position of the camera with respect to the marker. But then this value changes when I roll the camera (there is no pan, tilt). The value of the translation should be the same (since the physical location of the camera is the same) but in my case it changes with the roll...

I have also calculated (and displaying) the roll based on the rotation matrix and it gives me perfect angles...but how do I correct the translation matrix...
(eg. if there is a roll of 45 the camera position changes as if the pattern as moved when it should be the same... )

Should I use the orientation matrix to correct for this in some way... Please advise...

Sasha
Student, UIC

djoele
June 29th, 2005, 06:52 PM
I don?t know if this is comparable, but....

I want to use the transformation matrix from a camera that is not horizontal but is rotated over an angle (so the only thing that changed is the pitch). I want to change that matrix so that it would be the same when the camera would be horizontal.

Is there a way to convert between the two matrices?

djoele
June 30th, 2005, 09:42 PM
Can anybody help me how to implement a pitch of a camera?

I think I should change something about the transformation matrix.
I thought I should rotate the "up" and "look" vector, but in the
matrix, where can I find that? Are those one of the columns?

Or should I do something else?

djoele
June 30th, 2005, 10:28 PM
Does the following do a pitch of the camera of "angle" degrees?
I use the second and third column of the transformation matrix.
I rotate these vectors around the x axis (the -sin and cos).

The result is a shift of the drawn object upwards. It seems to get a bit smaller
and its orientation changes. See the attached image.
Is this the result a pitch should cause? I used an angle of 45 degrees in the
image.

Save1= CAMERA[0].patt_trans[1][1];
CAMERA[0].patt_trans[1][1]=cos(angle)*CAMERA[0].patt_trans[1][1]+sin(angle)*CAMERA[0].patt_trans[2][1];
CAMERA[0].patt_trans[2][1]=-sin(angle)*(Save1)+cos(angle)*CAMERA[0].patt_trans[2][1];

Save2 = CAMERA[0].patt_trans[1][2];
CAMERA[0].patt_trans[1][2]=cos(angle)*CAMERA[0].patt_trans[1][2]+sin(angle)*CAMERA[0].patt_trans[2][2];
CAMERA[0].patt_trans[2][2]=-sin(angle)*(SAve2)+cos(angle)*CAMERA[0].patt_trans[2][2];

KonkDev
July 5th, 2005, 01:34 PM
Hello everybody,

I am also experimenting with a static marker with a moving camera.

I used the code from the second post to get the inverse of the matrix. Then I calculated the axis-angle out of the matrix according to default 3D-space operations (like described in http://www.euclideanspace.com/maths/geometry/rotations/conversions/matrixToAngle/index.htm)

But the output is.... strange and wildly fluctuating.
(I also tried to use the "original" matrix I got by arGetTransMat, but the output also seems to be disturbed like in the first post)

Is there another possibility to get the orientation in axis-angle format out of the matrix?
Or may there be right- left-handed issues? ARToolit is righthanded, isn't it?!

djoele
July 5th, 2005, 08:34 PM
In the rotation of the axes I first negate the z-coordinate (because the z values are negative).
Then I do the rotation and in the end I negate the resulting z-values again.
Would that result in a pitch of the camera? Anybody can help?

Save1= CAMERA[0].patt_trans[1][1];
CAMERA[0].patt_trans[1][1]=cos(angle)*CAMERA[0].patt_trans[1][1]+sin(angle)*-CAMERA[0].patt_trans[2][1];
CAMERA[0].patt_trans[2][1]=-(-sin(angle)*(Save1)+cos(angle)*-CAMERA[0].patt_trans[2][1]);

Save2 = CAMERA[0].patt_trans[1][2];
CAMERA[0].patt_trans[1][2]=cos(angle)*CAMERA[0].patt_trans[1][2]+sin(angle)*-CAMERA[0].patt_trans[2][2];
CAMERA[0].patt_trans[2][2]=-(-sin(angle)*(SAve2)+cos(angle)*-CAMERA[0].patt_trans[2][2]);