nutonomy / nuscenes-devkit

The devkit of the nuScenes dataset.
https://www.nuScenes.org
Other
2.19k stars 616 forks source link

correct_yaw confusion - can you please provide a definitive answer when to use it - since it seems inconsistently used throughout codebase? #1038

Closed semirelezovikj closed 3 months ago

semirelezovikj commented 4 months ago

correct_yaw's docstring says this function is needed due to the fact that nuScenes maps were flipped over the y-axis. However, either I am missing something or its usage is inconsistently applied throughout the code.

This function is used in the make_representation method in the StaticLayerRasterizer class in the following manner:

yaw = quaternion_yaw(Quaternion(sample_annotation['rotation']))
yaw_corrected = correct_yaw(yaw)

#  later in code
angle_in_degrees = angle_of_rotation(yaw_corrected) * 180 / np.pi

Places where it is not used:

  1. function convert_global_coords_to_local uses angle_of_rotation directly on the yaw, no correction. calls make_2d_rotation_matrix using that
yaw = angle_of_rotation(quaternion_yaw(Quaternion(rotation)))
transform = make_2d_rotation_matrix(angle_in_radians=yaw)
  1. function convert_local_coords_to_global same, calls make_2d_rotation_matrix using the negative of the angle_of_rotation:
yaw = angle_of_rotation(quaternion_yaw(Quaternion(rotation)))
transform = make_2d_rotation_matrix(angle_in_radians=-yaw)

As you may imagine, this can cause quite some confusion.

whyekit-motional commented 3 months ago

@semirelezovikj in general, correct_yaw is used when coordinate data (i.e (x,y)) is used together with the maps

This is because the maps are essentially images and hence (0, 0) is at the top-left with the positive y-direction extending "downwards", e.g.:

[
    [0, 0, 0, 0, 0, 0, 0, 0, 0, 0],  # -y
    [0, 2, 2, 2, 2, 2, 2, 2, 2, 0],
    [0, 1, 1, 1, 1, 1, 1, 1, 1, 0],
    [0, 1, 1, 1, 1, 1, 1, 1, 1, 0],
    [0, 1, 1, 1, 1, 1, 1, 1, 1, 0],
    [0, 1, 1, 1, 1, 1, 1, 1, 1, 0],
    [0, 1, 1, 1, 1, 1, 1, 1, 1, 0],
    [0, 1, 1, 1, 1, 1, 1, 1, 1, 0],
    [0, 1, 1, 1, 1, 1, 1, 1, 1, 0],
    [0, 0, 0, 0, 0, 0, 0, 0, 0, 0],  # +y
],

However, for coordinate data, the positive y-direction would extend "upwards" instead