Skip to content

Parsing

parsing

Functions

make_4x4_transform(rotation_str, translation_str, scale_str='1')

Convenience function to make a 4x4 matrix from the string format used by Metashape

Parameters:

Name Type Description Default
rotation_str str

Row major with 9 entries

required
translation_str str

3 entries

required
scale_str str

single value. Defaults to "1".

'1'

Returns:

Type Description

np.ndarray: (4, 4) A homogenous transform mapping from cam to world

Source code in geograypher/utils/parsing.py
def make_4x4_transform(rotation_str: str, translation_str: str, scale_str: str = "1"):
    """Convenience function to make a 4x4 matrix from the string format used by Metashape

    Args:
        rotation_str (str): Row major with 9 entries
        translation_str (str): 3 entries
        scale_str (str, optional): single value. Defaults to "1".

    Returns:
        np.ndarray: (4, 4) A homogenous transform mapping from cam to world
    """
    rotation_np = np.fromstring(rotation_str, sep=" ")
    rotation_np = np.reshape(rotation_np, (3, 3))

    if not np.isclose(np.linalg.det(rotation_np), 1.0, atol=1e-8, rtol=0):
        raise ValueError(
            f"Inproper rotation matrix with determinant {np.linalg.det(rotation_np)}"
        )

    translation_np = np.fromstring(translation_str, sep=" ")
    scale = float(scale_str)
    transform = np.eye(4)
    transform[:3, :3] = rotation_np * scale
    transform[:3, 3] = translation_np
    return transform