From 736ba6d1f4ce5b41ef70ff8dc4abd332407ed35f Mon Sep 17 00:00:00 2001 From: John Lambert Date: Wed, 30 Jun 2021 16:25:44 -0400 Subject: [PATCH 1/4] use argoverse.utils.transform's yaw_to_quaternion3d instead of `quaternion` module --- argoverse/evaluation/competition_util.py | 31 +++++++++++++++--------- 1 file changed, 19 insertions(+), 12 deletions(-) diff --git a/argoverse/evaluation/competition_util.py b/argoverse/evaluation/competition_util.py index 23c64f9d..f7e4fb86 100644 --- a/argoverse/evaluation/competition_util.py +++ b/argoverse/evaluation/competition_util.py @@ -10,14 +10,14 @@ import h5py import numpy as np -import quaternion from scipy.spatial import ConvexHull from shapely.geometry import Polygon -from sklearn.cluster.dbscan_ import DBSCAN +from sklearn.cluster import DBSCAN from argoverse.data_loading.argoverse_tracking_loader import ArgoverseTrackingLoader from argoverse.data_loading.object_label_record import ObjectLabelRecord from argoverse.utils.se3 import SE3 +from argoverse.utils.transform import yaw_to_quaternion3d TYPE_LIST = Union[List[np.ndarray], np.ndarray] @@ -169,7 +169,15 @@ def dist(p1: Tuple[float, float], p2: Tuple[float, float]) -> float: def poly_to_label(poly: Polygon, category: str = "VEHICLE", track_id: str = "") -> ObjectLabelRecord: - # poly in polygon format + """Convert a Shapely Polygon to a 3d cuboid by estimating the minimum-bounding rectangle. + + Args: + poly: Shapely polygon object representing a convex hull of an object + category: object category to which object belongs, e.g. VEHICLE, PEDESTRIAN, etc + track_id: unique identifier + Returns: + object representing a 3d cuboid + """ bbox = poly.minimum_rotated_rectangle @@ -182,6 +190,7 @@ def poly_to_label(poly: Polygon, category: str = "VEHICLE", track_id: str = "") d1 = dist((x[0], y[0]), (x[1], y[1])) d2 = dist((x[1], y[1]), (x[2], y[2])) + # assign orientation so that the rectangle's longest side represents the object's length width = min(d1, d2) length = max(d1, d2) @@ -190,7 +199,8 @@ def poly_to_label(poly: Polygon, category: str = "VEHICLE", track_id: str = "") else: unit_v = unit_vector((x[0], y[0]), (x[1], y[1])) - angle = math.atan2(unit_v[1], unit_v[0]) + angle_rad = np.arctan2(unit_v[1], unit_v[0]) + q = yaw_to_quaternion3d(angle_rad) height = max(z) - min(z) @@ -205,10 +215,11 @@ def poly_to_label(poly: Polygon, category: str = "VEHICLE", track_id: str = "") ] ) - q = quaternion.from_rotation_matrix(R) + # location of object in egovehicle coordinates + center = np.array([centroid[0], centroid[1], min(z) + height / 2]) return ObjectLabelRecord( - quaternion=quaternion.as_float_array(q), + quaternion=q, translation=center, length=length, width=width, @@ -266,18 +277,14 @@ def save_label(argoverse_data: ArgoverseTrackingLoader, labels: List[ObjectLabel timestamp = argoverse_data.lidar_timestamp_list[idx] for label in labels: + qw, qx, qy, qz = label.quaternion json_data = { "center": { "x": label.translation[0], "y": label.translation[1], "z": label.translation[2], }, - "rotation": { - "x": label.quaternion[0], - "y": label.quaternion[1], - "z": label.quaternion[2], - "w": label.quaternion[3], - }, + "rotation": {"x": qx, "y": qy, "z": qz, "w": qw}, "length": label.length, "width": label.width, "height": label.height, From 3240dddbd3faab771397e66824c41fc0adaaad79 Mon Sep 17 00:00:00 2001 From: John Lambert Date: Wed, 30 Jun 2021 16:28:47 -0400 Subject: [PATCH 2/4] fix typo --- argoverse/evaluation/competition_util.py | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/argoverse/evaluation/competition_util.py b/argoverse/evaluation/competition_util.py index f7e4fb86..992db52d 100644 --- a/argoverse/evaluation/competition_util.py +++ b/argoverse/evaluation/competition_util.py @@ -204,7 +204,7 @@ def poly_to_label(poly: Polygon, category: str = "VEHICLE", track_id: str = "") height = max(z) - min(z) - # translation = center + # location of object in egovehicle coordinates center = np.array([bbox.centroid.xy[0][0], bbox.centroid.xy[1][0], min(z) + height / 2]) R = np.array( @@ -215,9 +215,6 @@ def poly_to_label(poly: Polygon, category: str = "VEHICLE", track_id: str = "") ] ) - # location of object in egovehicle coordinates - center = np.array([centroid[0], centroid[1], min(z) + height / 2]) - return ObjectLabelRecord( quaternion=q, translation=center, From 529365c95aed0539151609afed673effed73373f Mon Sep 17 00:00:00 2001 From: John Lambert Date: Wed, 30 Jun 2021 16:42:04 -0400 Subject: [PATCH 3/4] fix typo --- argoverse/evaluation/competition_util.py | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/argoverse/evaluation/competition_util.py b/argoverse/evaluation/competition_util.py index 992db52d..837a409c 100644 --- a/argoverse/evaluation/competition_util.py +++ b/argoverse/evaluation/competition_util.py @@ -204,17 +204,22 @@ def poly_to_label(poly: Polygon, category: str = "VEHICLE", track_id: str = "") height = max(z) - min(z) - # location of object in egovehicle coordinates + # translation = center center = np.array([bbox.centroid.xy[0][0], bbox.centroid.xy[1][0], min(z) + height / 2]) + c = np.cos(angle_rad) + s = np.sin(angle_rad) R = np.array( [ - [np.cos(angle), -np.sin(angle), 0], - [np.sin(angle), np.cos(angle), 0], + [c, -s, 0], + [s, c, 0], [0, 0, 1], ] ) + # location of object in egovehicle coordinates + center = np.array([centroid[0], centroid[1], min(z) + height / 2]) + return ObjectLabelRecord( quaternion=q, translation=center, From 47c3258371c7329cdcec6eede66c8df0c67c68b6 Mon Sep 17 00:00:00 2001 From: John Lambert Date: Wed, 30 Jun 2021 16:43:56 -0400 Subject: [PATCH 4/4] fix typo --- argoverse/evaluation/competition_util.py | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/argoverse/evaluation/competition_util.py b/argoverse/evaluation/competition_util.py index 837a409c..f88d47a1 100644 --- a/argoverse/evaluation/competition_util.py +++ b/argoverse/evaluation/competition_util.py @@ -204,7 +204,7 @@ def poly_to_label(poly: Polygon, category: str = "VEHICLE", track_id: str = "") height = max(z) - min(z) - # translation = center + # location of object in egovehicle coordinates center = np.array([bbox.centroid.xy[0][0], bbox.centroid.xy[1][0], min(z) + height / 2]) c = np.cos(angle_rad) @@ -217,9 +217,6 @@ def poly_to_label(poly: Polygon, category: str = "VEHICLE", track_id: str = "") ] ) - # location of object in egovehicle coordinates - center = np.array([centroid[0], centroid[1], min(z) + height / 2]) - return ObjectLabelRecord( quaternion=q, translation=center,