[Python] How to convert a bundle-adjusted pose to a reference pose in Metashape

Discussão em 'Python' iniciado por Stack, Maio 21, 2025.

  1. Stack

    Stack Membro Participativo

    I cannot convert the bundle-adjusted camera pose to a reference pose.

    First, I loaded several hundred images into Metashape, then imported the location (local coordinates) and poses (YPR-axis) for each image from a CSV file.

    Next, I ran bundle adjustment and the error for each camera pose converged to near zero compared to the imported pose.

    To evaluate this, I wrote the Python program to obtain the bundle-adjusted pose. However, this obtained pose don't match the reference (imported) poses. It seems like that the Z axis reverse. What's causing this and how can I fix it?

    Python code:

    import Metashape
    import math
    number = 100
    chunk = Metashape.app.document.chunk
    camera = chunk.cameras[number]
    T = Metashape.app.document.chunk.transform.matrix
    R = Metashape.app.document.chunk.cameras[number].transform.rotation()
    R_local = T.rotation() * R
    angles_local = Metashape.utils.mat2euler(R_local)
    print("Local angles:", angles_local)
    print("Ref angles:", Metashape.app.document.chunk.cameras[number].reference.rotation)

    camera_center_local = Metashape.app.document.chunk.cameras[number].transform.translation()
    camera_center_local = T.mulp(camera_center_local)
    print(f"Camera: {camera.label}, Position (local): {camera_center_local}")
    print(f"Camera: {camera.label}, Position (ref): {Metashape.app.document.chunk.cameras[number].reference.location}")



    Results:

    Local angles: Vector([91.3652986029176, 5.835493828982221, 179.40306681334])
    Ref angles: Vector([-90.00001, 20.00002, 0.0])
    Camera: 100_left, Position (local): Vector([10.366040133032797, -0.7933790621239181, 28.126534944902897])
    Camera: 100_left, Position (ref): Vector([10.24312, -0.75, 28.14286])

    Continue reading...

Compartilhe esta Página