MoI discussion forum
MoI discussion forum

Full Version: Setting camera from 3D scanner

From: track
29 Aug 2017   [#1]
Hi

I'm trying to set the camera of Moi to have the same position and orientation as the one I have with a 3D scanner.
The 3D scanner gives me R and T for a camera. (Each point is transformed as R * P + T).

I know the position of the camera which is given by Xc = -tranpose(R) * T
The viewing direction is given by the third row and the up vector is given by the second row.
How can set them in Moi ?
From: bemfarmer
29 Aug 2017   [#2] In reply to [#1]
Hi track,
Camera position (eye point),
Lookat point,
Focal Length
Viewport, vp
Field of view Angle, (1/2?),
are setup in Michaels script here:
http://moi3d.com/forum/index.php?webtag=MOI&msg=8476.3

As I know little about cameras, I'm going to do some Wikipedia reading:-)

- Brian
From: track
29 Aug 2017   [#3] In reply to [#2]
Thanks

I already saw that I can set the eye and lookat position with this script.
But I don't know how to set the leftRightAngle, upDownAngle and tiltAngle to get the correct orientation with the matrix R,T
From: bemfarmer
29 Aug 2017   [#4] In reply to [#1]
Hi track,

Do you have a link to the mathematics, the matrix, and the scanner setup?
R = rotation matrix? Is the camera or the target rotating?
P = a point?
T = a translation, or movement of the camera?

- Brian
From: bemfarmer
29 Aug 2017   [#5] In reply to [#3]
Hi track,
Isn't the left/right angle = field of view angle (x2?).
The other two look like they could be calculated by doing some trigonometry math?

Can you better describe the terms and the matrix, and the camera/laser/target setup, or do you have a link with pictures?

- Brian
From: track
29 Aug 2017   [#6] In reply to [#5]
I know how to compute the field of view from the intrinsic parameters of the camera.

I know:
1) How to compute and set the eye position from my (R, T) matrix
2) How to compute and set the lookat position from my (R,T) matrix
3) How to compute and set the field of view from the internal matrix K

In a 3D scanner, the application reconstructs a 3D model and computes the position/orientation of each camera (R, T).
For each point of the 3D model X , we have the following transformations (using matlab notation):

(u, v, w)' = K * (R * X + T)

with K = [ fx 0 cx; 0 fy cy; 0 0 1]
R = [rx; ry; rz]
and T

fx, fy are focal length
cx, cy principal point (the centre of projection)
R rotation matrix, T translation vector that map points in 3D world in the camera space.
u, v projection in the image

From this equation, it is easy to see that the position of the camera expressed in 3D world is -R'*T
The viewing direction expressed in the 3D world is rz, the "up" vector is ry and the "right" vector is rx.

Today in Moi, I can set the position, the target and the field of view. But I don't know how to handle the leftRightAngle, upDownAngle and tiltAngle to get the same orientation.
From: bemfarmer
29 Aug 2017   [#7] In reply to [#6]
I need more study and information.
[rx, ry, rz] is "arbitrary rotation axis," not a rotation matrix, but [Rx] [Ry] and [Rz] can be individual 3x3 rotation matrices.
So the camera rotates left to right, and tilts up and down, and could also roll, and also Translate in 3d space.
The laser is rigidly mounted to the camera at some distance D from the camera?
The target sits at say the origin.

This link has pitch and roll trig:
https://pdfs.semanticscholar.org/3046/e4b57081ce9fd51b6a96012219f454ac3e88.pdf

- Brian
From: Michael Gibson
29 Aug 2017   [#8] In reply to [#3]
Hi track,

> I already saw that I can set the eye and lookat position with this script.
> But I don't know how to set the leftRightAngle, upDownAngle and tiltAngle to get the correct orientation with the matrix R,T

You wouldn't set leftRightAngle and upDownAngle if you're setting the eye and lookat position already. The leftRightAngle and upDownAngle are basically just a way to use sphereical coordinates to set the viewing direction, you would use one of those methods or the other to define the camera direction, not both.

But the eye and lookat positions will only define a viewing direction and not a "roll" (https://en.wikipedia.org/wiki/Aircraft_principal_axes) around that direction, that is what tiltAngle can be used to set though.

- Michael
From: Michael Gibson
29 Aug 2017   [#9] In reply to [#6]
Hi track,

> The viewing direction expressed in the 3D world is rz, the "up" vector is ry and the "right" vector is rx.
>
> Today in Moi, I can set the position, the target and the field of view. But I don't know how to handle the
> leftRightAngle, upDownAngle and tiltAngle to get the same orientation.

So hopefully this is correct, I'm not thoroughly double checking it at the moment, but once you have set the position and target in MoI the viewing direction should match your rz and that also means you don't want to mess with the leftRightAngle and upDownAngle after that since they are alternate ways of setting the viewing direction.

Then tiltAngle will control the "up" direction's rotation around the view direction with respect to the world z axis direction.

The way the tilt angle is calculated is like this:

TempRight = CrossProduct( ViewDir, WorldZAxis )
if (TempRight.isDegenerate() )
TempRight = CrossProduct( ViewDir, WorldYAxis )

TempRight.Normalize()

NoTiltUpDir = CrossProduct( TempRight, ViewDir ).Normalize();


That's what will be the view's up direction for a "tiltAngle" of 0, you'd need to measure the angle between your view's up direction and that to get the angle to set to make them match.

Hope that helps!

- Michael
From: track
29 Aug 2017   [#10] In reply to [#7]
[rx; ry; rz] is a general rotation matrix. I'm using matlab notation
rx is the first row of my rotation matrix.
ry is the second row of my rotation matrix
ry is the third row of my rotation matrix
In my scanner there is no laser
From: track
29 Aug 2017   [#11] In reply to [#9]
Thanks this is what I was looking for.
From: bemfarmer
29 Aug 2017   [#12] In reply to [#10]
This link shows Matlab notation which appears to be like rx, ry, rz, as far as I can tell.
https://math.stackexchange.com/questions/219864/matlab-function-rotation-matrix

google search of "matlab rotation matrix 3d" brings up all sorts of good information and code, but your questions were answered by Michael :-)
- Brian
From: track
30 Aug 2017   [#13] In reply to [#12]
Your link is about contructing a rotation matrix along a given axis and with a given angle.
It is a general formula to build a rotation matrix

In my case, rx, ry and rz are three 3D vectors.
They are the rows of my rotation matrix.

Michael answered by question.