Hi Murray,
if you are importing external orientation as XYZOPK (Omega Phi Kappa) then you should change following line of code:
rot = Metashape.utils.ypr2mat(camera.reference.rotation) * Metashape.Matrix().Diag([1, -1, -1])
by:
rot = Metashape.utils.opk2mat(camera.reference.rotation) * Metashape.Matrix().Diag([1, -1, -1])
and it should work...
a more general way is to use euler2mat utility which would work whatever euler angle convention is used for orientation (YawPitchRoll, OmegaPhiKappa, PhiKappaOmega or AlphaNuKappa) defined by chunk.euler_angles as in:
rot = Metashape.utils.euler2mat(camera.reference.rotation, chunk.euler_angles) * Metashape.Matrix().Diag([1, -1, -1])