Forum

Author Topic: Rotating camera poses?  (Read 14666 times)

RalfH

  • Sr. Member
  • ****
  • Posts: 344
    • View Profile
Rotating camera poses?
« on: February 05, 2013, 11:25:36 AM »
I would like to rotate the camera poses by exporting the cameras.xml file, edit the values in the transformations section and re-import the file. Rotating the XYZ camera coordinates is not a problem (multiply with a rotation matrix), but does anybody know how to rotate the r11, r12, r13... parameters by the same angles?

Alexey Pasumansky

  • Agisoft Technical Support
  • Hero Member
  • *****
  • Posts: 14817
    • View Profile
Re: Rotating camera poses?
« Reply #1 on: February 05, 2013, 02:07:04 PM »
Hello RalfH,

In general the problem could be solved by multiplying coordinate transformation matrix (4x4) by camera transform matrix (4x4).
But could you please describe the problem you are trying to solve in this way, maybe there is more easier solution?
Best regards,
Alexey Pasumansky,
Agisoft LLC

RalfH

  • Sr. Member
  • ****
  • Posts: 344
    • View Profile
Re: Rotating camera poses?
« Reply #2 on: February 05, 2013, 02:44:38 PM »
Hello Alexey,

I am working with the standard edition, so I have to deal with the arbitrary coordinate system set up by PhotoScan during image alignment. But sometimes I want to specify which is "up" or "down" (i.e. control the way the model is aligned with respect to the Z axis of the coordinate system), so I thought I could align the model, export cameras, then rotate the cameras in a way that the Z axis really represents the up-down direction of the model, then re-import cameras and then build the model. But I'm not sure how to deal with the r parameters which specify the direction in which the cameras are looking. I assume that these have to be rotated as well. What do you think?

Alexey Pasumansky

  • Agisoft Technical Support
  • Hero Member
  • *****
  • Posts: 14817
    • View Profile
Re: Rotating camera poses?
« Reply #3 on: February 05, 2013, 03:33:21 PM »
Hello RalfH,

If you wish only to change Z axis direction you need to multiply camera transform by the following matrix from left:
(1, 0, 0, 0)
(0,-1, 0, 0)
(0, 0,-1, 0)
(0, 0, 0, 1)

Or just change signs for second and third lines in each camera transform matrix (elements 5 - 12).
Let me know if it works correctly for your needs.
Best regards,
Alexey Pasumansky,
Agisoft LLC

RalfH

  • Sr. Member
  • ****
  • Posts: 344
    • View Profile
Re: Rotating camera poses?
« Reply #4 on: February 05, 2013, 04:42:10 PM »
Hello Alexey,

do I understand you correctly that this will just flip up and down directions? But how can I rotate by a certain angle? E.g., I know the real-world camera positions and the modelled camera positions, and from this I can compute a rotation matrix (using, for example, JavaGraticule3D) with which I can rotate the camera positions. But what about the camera r parameters? Do they also simply go into the camera matrix?

P.S.: Sorry if this is a stupid question, but to me matrix algebra belongs into the realm of advanced magic...
« Last Edit: February 05, 2013, 04:44:03 PM by RalfH »

Alexey Pasumansky

  • Agisoft Technical Support
  • Hero Member
  • *****
  • Posts: 14817
    • View Profile
Re: Rotating camera poses?
« Reply #5 on: February 05, 2013, 06:03:50 PM »
Hello RalfH,

You can check General rotation section in the Wikipedia article: http://en.wikipedia.org/wiki/Rotation_matrix#General_rotations

3 x 3 matrix for the arbitrary rotation angles would be a top-left part of 4 x 4 matrix (the most bottom and right elements will be the same as in the previous example).
Best regards,
Alexey Pasumansky,
Agisoft LLC

RalfH

  • Sr. Member
  • ****
  • Posts: 344
    • View Profile
Re: Rotating camera poses?
« Reply #6 on: February 05, 2013, 07:35:17 PM »
So the 4 x 4 camera matrix would be this:

(r11 r12 r13 X)
(r21 r22 r23 Y)
(r31 r32 r33 Z)
(0     0     0   1)

where r11...r33 and XYZ are from the cameras.xml file,

and the rotation matrix (as adapted from the Wikipedia article) would be this:

(cosB*cosA    -cosG*sinA+sinG*sinB*cosA      sinG*sinA+cosG*sinB*cosA)
(cosB*sinA     cosG*cosA+sinG*sinB*sinA      -sinG*cosA+cosG*sinB*sinA)
(-sinB                      sinG*cosB                                  cosG*cosB                 )

where A, B and C are the angles by which the cameras and their viewing directions will be rotated?

Or am I getting it wrong?

Infinite

  • Sr. Member
  • ****
  • Posts: 366
    • View Profile
Re: Rotating camera poses?
« Reply #7 on: February 06, 2013, 02:39:00 PM »
Really I think this issue needs to be addressed in Standard Version as a basic requirement. Users really need to be able to control a scenes scale, orientation and position to how they need. Possibly along with a grid layout which can be visually controlled with scale, number of squares etc. With an indication to x,y,z and 0,0,0 in worldspace.

Related to this Feature request:

http://www.agisoft.ru/forum/index.php?topic=592.0

Having to input numbers and matrices is too complex. We need a UI tool. Luckily I have some scripts (thanks to Alexey and his team) to do it using the Region box but it's not ideal and only works for Pro.
_______________________________________________
I N F I N I T E
www.ir-ltd.net

Alexey Pasumansky

  • Agisoft Technical Support
  • Hero Member
  • *****
  • Posts: 14817
    • View Profile
Re: Rotating camera poses?
« Reply #8 on: February 06, 2013, 02:43:47 PM »
Hello RalfH,

Assuming that Rxy is rotation matrix and M is camera transform matrix from xml, you need to create the following transformation matrix T:

(R11 R12 R13 0)
(R21 R22 R23 0)
(R31 R32 R33 0)
(0     0     0     1)

and multiply it on M:

(r11 r12 r13 X)
(r21 r22 r23 Y)
(r31 r32 r33 Z)
(0     0     0   1)
Best regards,
Alexey Pasumansky,
Agisoft LLC

Mr_Curious

  • Jr. Member
  • **
  • Posts: 86
    • View Profile
Re: Rotating camera poses?
« Reply #9 on: February 06, 2013, 02:50:54 PM »
Really I think this issue needs to be addressed in Standard Version as a basic requirement. Users really need to be able to control a scenes scale, orientation and position to how they need. Possibly along with a grid layout which can be visually controlled with scale, number of squares etc. With an indication to x,y,z and 0,0,0 in worldspace.

Related to this Feature request:

http://www.agisoft.ru/forum/index.php?topic=592.0

Having to input numbers and matrices is too complex. We need a UI tool. Luckily I have some scripts (thanks to Alexey and his team) to do it using the Region box but it's not ideal and only works for Pro.

+1  I totally agree !!!

eduardoestrada85

  • Newbie
  • *
  • Posts: 37
    • View Profile
Re: Rotating camera poses?
« Reply #10 on: February 07, 2013, 07:01:13 AM »
++++++++1 for Infinite suggestion

RalfH

  • Sr. Member
  • ****
  • Posts: 344
    • View Profile
Re: Rotating camera poses?
« Reply #11 on: February 07, 2013, 11:14:19 AM »
Yes, that would really help a lot. I will try to work with the rotation matrices (thanks, Alexey!) as soon as I find the time for it (doesn't seem to be something that's done along the way), but of course being able to control the coordinate system in PhotoScan would be much better!