Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

nans in the retrieved extrinsic and values flipped from what it was set to #7043

Open
3 tasks done
mbspng opened this issue Nov 5, 2024 · 0 comments
Open
3 tasks done
Labels

Comments

@mbspng
Copy link

mbspng commented Nov 5, 2024

Checklist

My Question

When retrieving the extrinsic from the view control, after setting it, why do I get nans in the extrinsic and why is it flipped?

import numpy as np
import open3d
from open3d.visualization import ViewControl


np.set_printoptions(precision=2, suppress=True)


def main():
    vis = open3d.visualization.Visualizer()
    vis.create_window(visible=False)
    view_control: ViewControl = vis.get_view_control()

    vis.update_renderer()
    vis.poll_events()

    target = np.random.rand(3)

    extrinsics = construct_extrinsics(target)

    camera_parameters = view_control.convert_to_pinhole_camera_parameters()

    extrinsics_out = camera_parameters.extrinsic
    # no nans
    print(extrinsics_out)

    vis.update_renderer()
    vis.poll_events()

    camera_parameters.extrinsic = extrinsics
    result = view_control.convert_from_pinhole_camera_parameters(camera_parameters, allow_arbitrary=True)

    vis.update_renderer()
    vis.poll_events()

    assert result

    # no nans
    print(extrinsics)

    camera_parameters = view_control.convert_to_pinhole_camera_parameters()

    extrinsics_out = camera_parameters.extrinsic
    # nans
    print(extrinsics_out)


def construct_extrinsics(target: np.ndarray) -> np.ndarray:
    eye = np.zeros(3)
    forward = target - eye

    assert np.allclose(np.linalg.norm(forward), np.linalg.norm(target))

    forward /= np.linalg.norm(forward)

    up = np.array([0.0, 1.0, 0.0])
    right = np.cross(up, forward)
    up = np.cross(right, forward)

    up /= np.linalg.norm(up)
    right /= np.linalg.norm(right)

    assert up @ right < 1e-6
    assert up @ forward < 1e-6
    assert right @ forward < 1e-6

    rotation = np.array([right, up, forward])
    extrinsics = np.eye(4)
    extrinsics[:3, :3] = rotation
    extrinsics[:3, 3] = -(rotation @ eye)

    return extrinsics


if __name__ == "__main__":
    main()
# default
[[ 1.  0.  0. -0.]
 [-0. -1. -0.  0.]
 [-0. -0. -1.  0.]
 [ 0.  0.  0.  1.]]

# my input
[[ 0.49  0.   -0.87 -0.  ]
 [ 0.83 -0.31  0.47 -0.  ]
 [ 0.27  0.95  0.15 -0.  ]
 [ 0.    0.    0.    1.  ]]

# the output (with nans and flipped entries)
[[-0.49  0.    0.87   nan]
 [ 0.83 -0.31  0.47   nan]
 [ 0.27  0.95  0.15   nan]
 [ 0.    0.    0.    1.  ]]

open3d v0.18.0

@mbspng mbspng added the question label Nov 5, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant