-
Notifications
You must be signed in to change notification settings - Fork 366
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add map view to nuscenes python example (#8034)
<!-- Open the PR up as a draft until you feel it is ready for a proper review. Do not make PR:s from your own `main` branch, as that makes it difficult for reviewers to add their own fixes. Add any improvements to the branch as new commits to make it easier for reviewers to follow the progress. All commits will be squashed to a single commit once the PR is merged into `main`. Make sure you mention any issues that this PR closes in the description, as well as any other related issues. To get an auto-generated PR description you can put "copilot:summary" or "copilot:walkthrough" anywhere. --> ### What Small map in the nuscenes example. 👇 <img width="1222" alt="image" src="https://github.com/user-attachments/assets/01c9d830-a774-4ebf-9e73-612e57d488da"> ### Checklist * [x] I have read and agree to [Contributor Guide](https://github.com/rerun-io/rerun/blob/main/CONTRIBUTING.md) and the [Code of Conduct](https://github.com/rerun-io/rerun/blob/main/CODE_OF_CONDUCT.md) * [x] I've included a screenshot or gif (if applicable) * [x] I have tested the web demo (if applicable): * Using examples from latest `main` build: [rerun.io/viewer](https://rerun.io/viewer/pr/8034?manifest_url=https://app.rerun.io/version/main/examples_manifest.json) * Using full set of examples from `nightly` build: [rerun.io/viewer](https://rerun.io/viewer/pr/8034?manifest_url=https://app.rerun.io/version/nightly/examples_manifest.json) * [x] The PR title and labels are set such as to maximize their usefulness for the next release's CHANGELOG * [x] If applicable, add a new check to the [release checklist](https://github.com/rerun-io/rerun/blob/main/tests/python/release_checklist)! * [x] If have noted any breaking changes to the log API in `CHANGELOG.md` and the migration guide - [PR Build Summary](https://build.rerun.io/pr/8034) - [Recent benchmark results](https://build.rerun.io/graphs/crates.html) - [Wasm size tracking](https://build.rerun.io/graphs/sizes.html) To run all checks from `main`, comment on the PR with `@rerun-bot full-check`. --------- Co-authored-by: Antoine Beyeler <antoine@rerun.io>
- Loading branch information
Showing
3 changed files
with
139 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
86 changes: 86 additions & 0 deletions
86
examples/python/nuscenes_dataset/nuscenes_dataset/export_gps.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
# from nuScenes dev-kit: https://github.com/nutonomy/nuscenes-devkit/blob/4df2701feb3436ae49edaf70128488865a3f6ff9/python-sdk/nuscenes/scripts/export_poses.py | ||
# Code contributed by jean-lucas, 2020. | ||
|
||
"""Exports the nuScenes ego poses as "GPS" coordinates (lat/lon) for each scene into JSON or KML formatted files.""" | ||
|
||
from __future__ import annotations | ||
|
||
import math | ||
from typing import Sequence | ||
|
||
EARTH_RADIUS_METERS = 6.378137e6 | ||
REFERENCE_COORDINATES = { | ||
"boston-seaport": [42.336849169438615, -71.05785369873047], | ||
"singapore-onenorth": [1.2882100868743724, 103.78475189208984], | ||
"singapore-hollandvillage": [1.2993652317780957, 103.78217697143555], | ||
"singapore-queenstown": [1.2782562240223188, 103.76741409301758], | ||
} | ||
|
||
|
||
def get_coordinate(ref_lat: float, ref_lon: float, bearing: float, dist: float) -> tuple[float, float]: | ||
""" | ||
Using a reference coordinate, extract the coordinates of another point in space given its distance and bearing | ||
to the reference coordinate. For reference, please see: https://www.movable-type.co.uk/scripts/latlong.html. | ||
Parameters | ||
---------- | ||
ref_lat : float | ||
Latitude of the reference coordinate in degrees, e.g., 42.3368. | ||
ref_lon : float | ||
Longitude of the reference coordinate in degrees, e.g., 71.0578. | ||
bearing : float | ||
The clockwise angle in radians between the target point, reference point, and the axis pointing north. | ||
dist : float | ||
The distance in meters from the reference point to the target point. | ||
Returns | ||
------- | ||
tuple[float, float] | ||
A tuple of latitude and longitude. | ||
""" # noqa: D205 | ||
lat, lon = math.radians(ref_lat), math.radians(ref_lon) | ||
angular_distance = dist / EARTH_RADIUS_METERS | ||
|
||
target_lat = math.asin( | ||
math.sin(lat) * math.cos(angular_distance) + math.cos(lat) * math.sin(angular_distance) * math.cos(bearing) | ||
) | ||
target_lon = lon + math.atan2( | ||
math.sin(bearing) * math.sin(angular_distance) * math.cos(lat), | ||
math.cos(angular_distance) - math.sin(lat) * math.sin(target_lat), | ||
) | ||
return math.degrees(target_lat), math.degrees(target_lon) | ||
|
||
|
||
def derive_latlon(location: str, pose: dict[str, Sequence[float]]) -> tuple[float, float]: | ||
""" | ||
Extract lat/lon coordinate from pose. | ||
This makes the following two assumptions in order to work: | ||
1. The reference coordinate for each map is in the south-western corner. | ||
2. The origin of the global poses is also in the south-western corner (and identical to 1). | ||
Parameters | ||
---------- | ||
location : str | ||
The name of the map the poses correspond to, i.e., `boston-seaport`. | ||
pose : dict[str, Sequence[float]] | ||
nuScenes egopose. | ||
Returns | ||
------- | ||
tuple[float, float] | ||
Latitude and longitude coordinates in degrees. | ||
""" | ||
assert ( | ||
location in REFERENCE_COORDINATES.keys() | ||
), f"Error: The given location: {location}, has no available reference." | ||
|
||
reference_lat, reference_lon = REFERENCE_COORDINATES[location] | ||
x, y = pose["translation"][:2] | ||
bearing = math.atan(x / y) | ||
distance = math.sqrt(x**2 + y**2) | ||
lat, lon = get_coordinate(reference_lat, reference_lon, bearing, distance) | ||
|
||
return lat, lon |