| """ |
| This is a demo script that was used to take the default dynamicWorld.json and extract every vehicle with its related objects and sorts them |
| to a new json file for each ego vehicle. |
| This allows an analysis of each maneuver without accessing other vehicles in the dynamicWorld. |
| Please note that this will generate a lot of redundant information. |
| |
| """ |
| from openautomatumdronedata.dataset import droneDataset |
| import json |
| import os |
| import shutil |
| import sys |
|
|
| |
| dataset_folders = list() |
| current_path = os.path.abspath(os.path.join(__file__ ,"../..")) |
| for item in os.listdir(current_path): |
| if os.path.isdir(os.path.join(current_path, item)) and item != "img": |
| dataset_folders.append(item) |
|
|
|
|
|
|
| for recording_folder in dataset_folders: |
| path = os.path.join(current_path, recording_folder) |
|
|
| |
| export_path = os.path.join(current_path, recording_folder, "export_single_objects") |
| if not os.path.exists(export_path): |
| os.mkdir(export_path) |
|
|
| |
| dataset = droneDataset(path) |
|
|
| |
| dynWorld = dataset.dynWorld |
|
|
| |
| f = open(os.path.join(path, "dynamicWorld.json")) |
| json_dict = json.load(f) |
|
|
| |
| relation_dict = dict() |
|
|
| |
| for object in json_dict["objects"]: |
| """ |
| Now we access the object_relation_dict_list, ttc_dict and tth_dict of the object to see which objects are the surrounding ones: |
| "object_relation_dict_list": [ |
| { |
| "front_ego": null, |
| "behind_ego": "32499e60-30e9-4f41-8dc4-8699364db5dc", |
| "front_left": null, |
| "behind_left": null, |
| "front_right": "3e67c856-116a-4af5-96cc-39f5002f71a0", |
| "behind_right": "3002eaf3-a545-4e56-aa31-557f25e79643" |
| }, |
| ... |
| |
| "ttc_dict_vec": [ |
| { |
| "front_ego": -1, |
| "behind_ego": null, |
| "front_left": null, |
| "behind_left": null, |
| "front_right": 477.62466112341815, |
| "behind_right": null |
| }, |
| ... |
| |
| "tth_dict_vec": [ |
| { |
| "front_ego": null, |
| "behind_ego": 0.380621726114513, |
| "front_left": null, |
| "behind_left": null, |
| "front_right": -1, |
| "behind_right": 3.687973804225473 |
| }, |
| ... |
| """ |
| for i, (object_relation_dict, ttc_dict, tth_dict, lat_dict, long_dict) in enumerate(zip(object["object_relation_dict_list"], object["ttc_dict_vec"], object["tth_dict_vec"], object["lat_dist_dict_vec"], object["long_dist_dict_vec"])): |
| time_stamp = object["time"][i] |
| for key in object_relation_dict.keys(): |
| relation = object_relation_dict[key] |
| if relation is not None: |
| relation_object = dynWorld.get_dynObj_by_UUID(relation) |
| time_idx = relation_object.next_index_of_specific_time(time_stamp) |
|
|
|
|
| |
| relation_dict["UUID"] = relation_object.UUID |
| relation_dict["length"] = relation_object.length |
| relation_dict["width"] = relation_object.width |
| relation_dict["x"] = relation_object.x_vec[time_idx] |
| relation_dict["y"] = relation_object.y_vec[time_idx] |
| relation_dict["vx"] = relation_object.vx_vec[time_idx] |
| relation_dict["vy"] = relation_object.vy_vec[time_idx] |
| relation_dict["ax"] = relation_object.ax_vec[time_idx] |
| relation_dict["ay"] = relation_object.ay_vec[time_idx] |
| relation_dict["jerk_x"] = relation_object.vx_vec[time_idx] |
| relation_dict["jerk_y"] = relation_object.vx_vec[time_idx] |
| relation_dict["curvature"] = relation_object.vx_vec[time_idx] |
| relation_dict["psi"] = relation_object.psi_vec[time_idx] |
| relation_dict["lane_id"] = relation_object.lane_id_vec[time_idx] |
| relation_dict["road_id"] = relation_object.road_id_vec[time_idx] |
| relation_dict["road_type"] = relation_object.vx_vec[time_idx] |
| relation_dict["distance_left_lane_marking"] = relation_object.distance_left_lane_marking[time_idx] |
| relation_dict["distance_right_lane_marking"] = relation_object.distance_right_lane_marking[time_idx] |
| relation_dict["ttc"] = ttc_dict[key] |
| relation_dict["tth"] = tth_dict[key] |
| relation_dict["lat_dist"] = lat_dict[key] |
| relation_dict["long_dist"] = long_dict[key] |
|
|
| else: |
| relation_dict = None |
|
|
| |
| """ |
| Now we replace the initial single UUID of the object with all information we accumulated about the object behind the UUID |
| |
| "object_relation_dict_list": [ |
| { |
| "front_left": 0decabdc-fa4f-4f25-93ed-88eed734bba0, |
| ... |
| |
| "object_relation_dict_list": [ |
| { |
| "front_left": { |
| "UUID": "0decabdc-fa4f-4f25-93ed-88eed734bba0", |
| "length": 4.172288426073395, |
| "width": 1.8141249203213998, |
| "vx": 46.54388406290268, |
| "vy": 0.005328263922638854, |
| "ax": 0.5608367460027531, |
| "ay": -0.5516711364613421, |
| "psi": -0.5643746012832805, |
| "x": 47.834595023288536, |
| "y": -32.82371510377445, |
| "lane_id": 3, |
| "road_id": 0, |
| "distance_left_lane_marking": 2.3102357971463827, |
| "distance_right_lane_marking": 1.6230526113559351 |
| }, |
| --- |
| |
| """ |
| object["object_relation_dict_list"][i][key] = relation_dict |
|
|
| relation_dict = dict() |
|
|
|
|
| |
| del object["ttc_dict_vec"] |
| del object["tth_dict_vec"] |
| del object["lat_dist_dict_vec"] |
| del object["long_dist_dict_vec"] |
|
|
| |
| with open(os.path.join(export_path, object["UUID"] + ".json"), "w") as outfile: |
| json.dump(object, outfile) |
| print("Successfully exported object %s" % object["UUID"]) |
|
|
|
|
|
|
|
|