-
Notifications
You must be signed in to change notification settings - Fork 26
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
How to get the Lane Map? #45
Comments
hello, I also have the same problem, did you solve it? |
You could use the following code snippet to get the waymo map data. The output map is stored in waymo's global coordinate. Note that this data processing script is not in line with ChatSim, just for the case you want to extract the map data. import numpy as np
import tensorflow as tf
from pathlib import Path
from typing import List, Dict, Any, Union
from waymo_open_dataset import dataset_pb2, label_pb2
from waymo_open_dataset.utils import frame_utils
from google.protobuf import json_format
def extract_map_data(frame: dataset_pb2.Frame) -> Dict[str, Any]:
"""
frame.map_features have many MapFeature item
message MapFeature {
// A unique ID to identify this feature.
optional int64 id = 1;
// Type specific data.
oneof feature_data {
LaneCenter lane = 3; # polyline
RoadLine road_line = 4; # polyline
RoadEdge road_edge = 5; # polyline
StopSign stop_sign = 7;
Crosswalk crosswalk = 8; # polygon
SpeedBump speed_bump = 9; # polygon
Driveway driveway = 10; # polygon
}
}
Returns:
map_data: Dict
'lane': list of polylines, each polyline is noted by several vertices.
'road_line': list of polylines, each polyline is noted by several vertices.
...
"""
def hump_to_underline(hump_str):
import re
return re.sub(r'([a-z])([A-Z])', r'\1_\2', hump_str).lower()
map_features_list = json_format.MessageToDict(frame)['mapFeatures']
feature_names = ["lane", "road_line", "road_edge", "crosswalk", "speed_bump", "driveway"]
map_data = dict(zip(feature_names, [[] for _ in range(len(feature_names))]))
for feature in tqdm(map_features_list):
feature_name = list(feature.keys())
feature_name.remove("id")
feature_name = feature_name[0]
feature_name_lower = hump_to_underline(feature_name)
feature_content = feature[feature_name]
if feature_name_lower in ["lane", "road_line", "road_edge"]:
polyline = feature_content['polyline'] # [{'x':..., 'y':..., 'z':...}, {'x':..., 'y':..., 'z':...}, ...]
elif feature_name_lower in ["crosswalk", "speed_bump", "driveway"]:
polyline = feature_content['polygon'] # [{'x':..., 'y':..., 'z':...}, {'x':..., 'y':..., 'z':...}, ...]
else:
continue
polyline = [[point['x'], point['y'], point['z']] for point in polyline] # [[x, y, z], [x, y, z], ...]
map_data[hump_to_underline(feature_name)].append(polyline)
return map_data
def extract_map_data_from_one_scene(self, segment_tfrecord: Path, out_dir: Path) -> int:
dataset = tf.data.TFRecordDataset(segment_tfrecord.as_posix(), compression_type="")
for frame_idx, data in enumerate(dataset):
frame = dataset_pb2.Frame()
frame.ParseFromString(bytearray(data.numpy()))
if frame_idx == 0:
# only stored at the first frame
map_data = extract_map_data(frame)
return map_data |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hi,great works! I wonder how do you can the GT Lane Map? The paper mentioned that "Generally, we use the lane map from
the ground-truth data".
The text was updated successfully, but these errors were encountered: