facebookresearch / habitat-sim

A flexible, high-performance 3D simulator for Embodied AI research.
https://aihabitat.org/
MIT License
2.61k stars 420 forks source link

Image extractor quaternions are incorrect #2034

Open smorad opened 1 year ago

smorad commented 1 year ago

Habitat-Sim version

latest docker release

🐛 Bug

The ImageExtractor will flip the Y-axis direction if the rotation is close to 180 degrees. This means the agent flips upside-down and takes images from underneath the floor. There's already a code comment that refers to this:

https://github.com/facebookresearch/habitat-sim/blob/5fb04078b0b8432dc4a88ec186a2b7af74163be1/src_python/habitat_sim/utils/data/pose_extractor.py#L274

This can be fixed by rewriting the _compute_quat function to force the rotation about a specific axis (the y axis in our case):

    # Fixed implementation
    def _compute_quat(self, cam_normal: np.ndarray) -> qt.quaternion:
        v0 = habitat_sim.geo.FRONT
        v1 = cam_normal / np.linalg.norm(cam_normal)
        # Only care about y rotation
        theta = np.arccos(np.dot(v0, v1))
        return quat_from_angle_axis(theta, np.array([0, 1.0, 0]))

cc @janblumenkamp

dhruvbatra commented 1 year ago

Thanks for finding this. Would you mind sending a PR to fix it? And @mpiseno -- perhaps you could review the PR?