Forum

Author Topic: Script to disable cameras based on camera pitch  (Read 3138 times)

jgillan

  • Newbie
  • *
  • Posts: 12
    • View Profile
Script to disable cameras based on camera pitch
« on: July 18, 2019, 09:58:30 PM »
Hi Agisoft Community,
I am trying to write a headless mode script to identify and disable all cameras with a certain pitch. I want to do this because I use many nadir and oblique images to build 3D models of desert landscapes. I also build orthomosaics, but only need the nadir images to do so (to reduce processing time). This is the logic:

if Metashape.Camera.rotation(pitch) > 10:
    Metashape.Camera.enabled = False
else:
    Metashape.Camera.enabled = True

I just don't know how to correctly code this and refer to the pitch rotation.

Can anybody help?

Alexey Pasumansky

  • Agisoft Technical Support
  • Hero Member
  • *****
  • Posts: 14853
    • View Profile
Re: Script to disable cameras based on camera pitch
« Reply #1 on: July 18, 2019, 10:25:31 PM »
Hello jgillan,

Do you mean estimated pitch values?
Best regards,
Alexey Pasumansky,
Agisoft LLC

Alexey Pasumansky

  • Agisoft Technical Support
  • Hero Member
  • *****
  • Posts: 14853
    • View Profile
Re: Script to disable cameras based on camera pitch
« Reply #2 on: July 18, 2019, 10:29:34 PM »
Try this code:

Code: [Select]
import Metashape

chunk = Metashape.app.document.chunk
T = chunk.transform.matrix
m = chunk.crs.localframe(T.mulp(camera.center))
for camera in chunk.cameras:
R = (m * T * camera.transform * Metashape.Matrix().Diag([1, -1, -1, 1])).rotation()
estimated_ypr = Metashape.utils.mat2ypr(R)
if abs(estimated_ypr[1]) > 10:
camera.enabled = False
else:
camera.enabled = True
Best regards,
Alexey Pasumansky,
Agisoft LLC

jgillan

  • Newbie
  • *
  • Posts: 12
    • View Profile
Re: Script to disable cameras based on camera pitch
« Reply #3 on: July 19, 2019, 01:26:26 AM »
Thank you for the reply! I am referring to the metadata contained in the image exif. ‘Estimated’, per your code will give more or less the same answer?