vye16 / shape-of-motion

MIT License
801 stars 57 forks source link

Issues with Load Camera Path #30

Open xyzalanix opened 3 months ago

xyzalanix commented 3 months ago

Hi, beautiful repo, thanks for the work.

Sharing this for anyone who finds it helpful, I'm sure there's a cleaner solution.

I encountered this issue when loading previously saved camera paths:

File "/home/xxx/data/shape-of-motion/flow3d/vis/render_panel.py", line 999, in _
    frame["time"],
KeyError: 'time'

And found out it was related to the camera path json contents. "time" is found under camera_path and not under keyframes as the code assumes.

Kind of messy, but loading saved camera paths now works perfectly like this:

                    keyframes = json_data["keyframes"]
                    camera_path_time = json_data["camera_path"]
                    camera_path.reset()
                    for i in range(len(keyframes)):
                        frame = keyframes[i]
                        frame_time = camera_path_time[i]
                        # print(frame)
                        pose = tf.SE3.from_matrix(
                            np.array(frame["matrix"]).reshape(4, 4)
                        )
                        # # apply the x rotation by 180 deg
                        # pose = tf.SE3.from_rotation_and_translation(
                        #     pose.rotation() @ tf.SO3.from_x_radians(np.pi),
                        #     pose.translation(),
                        # )

                        camera_path.add_camera(
                            Keyframe(
                                frame_time["time"],
                                position=pose.translation(),
                                wxyz=pose.rotation().wxyz,
                                # There are some floating point conversions between degrees and radians, so the fov and
                                # default_Fov values will not be exactly matched.
                                override_fov_enabled=abs(
                                    frame["fov"] - json_data.get("default_fov", 0.0)
                                )
                                > 1e-3,
                                override_fov_rad=frame["fov"] / 180.0 * np.pi,
                                aspect=frame["aspect"],
                                override_transition_enabled=frame.get(
                                    "override_transition_enabled", None
                                ),
                                override_transition_sec=frame.get(
                                    "override_transition_sec", None
                                ),
                            )
                        )