Forum

Author Topic: Camera orientation  (Read 3960 times)

Llama

  • Newbie
  • *
  • Posts: 6
    • View Profile
Camera orientation
« on: November 07, 2019, 05:38:32 PM »
I am trying to get the direction vector of my cameras in what I think is the internal coordinate system, to go on to detect cameras that aligned facing upwards. Here is my current attempt:

Code: [Select]
for camera in chunk.cameras:
    if camera.transform and camera.selected:
        print(camera.transform.mulv(Metashape.Vector([0,0,1])).normalized())

I would expect the result in my screenshot to have a large -Z component, and low X and Y components since this camera is pointing straight down. However, it has quite significant X and Y components. I suspect I'm missing something obvious here, but any help would be appreciated.

Llama

  • Newbie
  • *
  • Posts: 6
    • View Profile
Re: Camera orientation
« Reply #1 on: November 07, 2019, 05:52:53 PM »
Also may I ask how to set the ground height in the Python API?

Alexey Pasumansky

  • Agisoft Technical Support
  • Hero Member
  • *****
  • Posts: 14813
    • View Profile
Re: Camera orientation
« Reply #2 on: November 07, 2019, 07:11:40 PM »
Hello Llama,

I suggest to use the following vector:
Code: [Select]
v = camera.transform.mulp(camera.sensor.calibration.unproject(Metashape.Vector([camera.sensor.width/2, camera.sensor.height/2]))) - camera.center
print(v.normalized())
Best regards,
Alexey Pasumansky,
Agisoft LLC

Llama

  • Newbie
  • *
  • Posts: 6
    • View Profile
Re: Camera orientation
« Reply #3 on: November 07, 2019, 08:05:38 PM »
Hello Llama,

I suggest to use the following vector:
Code: [Select]
v = camera.transform.mulp(camera.sensor.calibration.unproject(Metashape.Vector([camera.sensor.width/2, camera.sensor.height/2]))) - camera.center
print(v.normalized())

Hello Alexey, thank you for your response.

This gives a very similar vector. Is this vector in the same coordinate system as the 3 axes as in my screenshot?

In this screenshot I am looking down the X axis, and the camera clearly appears to be facing predominantly in the negative Z direction, why then is the Z positive and its Y component larger and negative?

Apologies if I'm missing something here

Alexey Pasumansky

  • Agisoft Technical Support
  • Hero Member
  • *****
  • Posts: 14813
    • View Profile
Re: Camera orientation
« Reply #4 on: November 07, 2019, 08:20:03 PM »
Hello Llama,

Is the chunk you are working with referenced or transformed (whether chunk.transform.matrix is not an identity matrix)?
Best regards,
Alexey Pasumansky,
Agisoft LLC

Llama

  • Newbie
  • *
  • Posts: 6
    • View Profile
Re: Camera orientation
« Reply #5 on: November 08, 2019, 12:47:56 PM »
Hello Llama,

Is the chunk you are working with referenced or transformed (whether chunk.transform.matrix is not an identity matrix)?

The chunk is referenced, chunk.transform.matrix is not the identity. If I perform chunk.transform.matrix.mulv( v ) the value is still not what I expect

Paulo

  • Hero Member
  • *****
  • Posts: 1303
    • View Profile
Re: Camera orientation
« Reply #6 on: November 09, 2019, 08:08:37 AM »
Hello Llama,

in fact both

camera.transform.mulv(Metashape.Vector([0,0,1])).normalized()

and

(camera.transform.mulp(camera.sensor.calibration.unproject(Metashape.Vector([camera.sensor.width/2 + camera.sensor.calibration.cx, camera.sensor.height/2 + camera.sensor.calibration.cy]))) - camera.center).normalized()

are equal because

camera.sensor.calibration.unproject(Metashape.Vector([camera.sensor.width/2 + camera.sensor.calibration.cx, camera.sensor.height/2 + camera.sensor.calibration.cy])) =  Metashape.Vector([0,0,1])


see following code looping over 3 selected cameras in Chunk:
Code: [Select]
In [5]: chunk = Metashape.app.document.chunk



In [6]: for camera in [camera for camera in chunk.cameras if camera.selected]:

   ...:     if not camera.transform:

   ...:         continue #skip NA cameras

   ...:     v1 = camera.transform.mulv(Metashape.Vector([0,0,1])).normalized()

   ...:     v2 = (camera.transform.mulp(camera.sensor.calibration.unproject(Metashape.Vector([camera.sensor.width/2 + camera.sensor.calibration.cx, camera.sensor.height/2 + camera.sensor.calibration.cy]))) - camera.center).normalized()

   ...:     print(v1,v2)

   ...:     

2019-11-08 23:29:52 Vector([-0.1033289536400215, -0.08265002582222386, -0.9912073953372443]) Vector([-0.10332895364002148, -0.08265002582222358, -0.9912073953372443])

2019-11-08 23:29:52 Vector([0.13798561502657053, -0.021950523948559043, -0.9901909636752514]) Vector([0.13798561502657047, -0.02195052394855912, -0.9901909636752514])

2019-11-08 23:29:52 Vector([-0.08735553645833521, -0.2356092436143632, -0.9679138879949727]) Vector([-0.08735553645833517, -0.23560924361436314, -0.9679138879949727])
« Last Edit: November 09, 2019, 10:10:10 AM by Paulo »
Best Regards,
Paul Pelletier,
Surveyor

Llama

  • Newbie
  • *
  • Posts: 6
    • View Profile
Re: Camera orientation
« Reply #7 on: December 19, 2019, 03:48:03 PM »
To solve this, I had to use the chunks coordinate system; the camera transform and chunk transform was not sufficient. I think 'internal coordinate system' turned out not to be what I wanted. Please see these links:
https://www.agisoft.com/forum/index.php?topic=7999.0
https://agisoft.freshdesk.com/support/solutions/articles/31000145016-how-to-calculate-estimated-exterior-orientation-parameters-for-the-cameras-using-python