1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586 |
- import pandas as pd
- import numpy as np
- import matplotlib.pyplot as plt
- import matplotlib.patches as patches
- from matplotlib.animation import FuncAnimation
- import os
- X_OFFSET = 258109.4239876
- Y_OFFSET = 4149969.964821
- csv_data_path = "/home/kevin/kevin/zhaoyuan/zhaoyuan/data/processed/data_zhaoyuan1"
- lane_map_df = pd.read_csv(os.path.join(csv_data_path, 'LaneMap.csv'))
- car_df = pd.read_csv(os.path.join(csv_data_path, 'ObjState.csv'))
- unique_vehicle_ids = car_df['playerId'].unique()
- colors = ['red', 'blue', 'green', 'orange', 'purple', 'cyan', 'magenta', 'yellow', 'black', 'brown']
- vehicle_colors = {vehicle_id: colors[i] for i, vehicle_id in enumerate(unique_vehicle_ids)}
- grouped_car_data = car_df.groupby("simTime")
- fig, ax = plt.subplots()
- ax.set_aspect("equal")
- ax.set_xlim([lane_map_df["centerLine_x"].min() - 20, lane_map_df["centerLine_x"].max() + 20])
- ax.set_ylim([lane_map_df["centerLine_y"].min() - 20, lane_map_df["centerLine_y"].max() + 20])
- ax.plot(lane_map_df["centerLine_x"], lane_map_df["centerLine_y"], color="red", linewidth=2, linestyle="--", label="Vehicle Center Line")
- ax.plot(lane_map_df["lane_left_x"], lane_map_df["lane_left_y"], color="blue", linewidth=2, label="Left Lane Line")
- ax.plot(lane_map_df["lane_right_x"], lane_map_df["lane_right_y"], color="blue", linewidth=2, label="Right Lane Line")
- def update(frame):
-
- for patch in ax.patches:
- patch.remove()
-
-
- current_time = list(grouped_car_data.groups.keys())[frame]
- current_data = grouped_car_data.get_group(current_time)
-
- for index, row in current_data.iterrows():
- posX = row['posX'] + X_OFFSET
- posY = row['posY'] + Y_OFFSET
- posH = row['posH']
- dimX = row['dimX']
- dimY = row['dimY']
-
- corners = np.array([
- [-dimX / 2, -dimY / 2],
- [dimX / 2, -dimY / 2],
- [dimX / 2, dimY / 2],
- [-dimX / 2, dimY / 2],
- ])
-
-
- rotation_matrix = np.array(
- [[np.cos(posH), np.sin(posH)], [-np.sin(posH), np.cos(posH)]]
- )
- rotated_corners = corners.dot(rotation_matrix) + np.array([posX, posY])
-
- vehicle_color = vehicle_colors[row['playerId']]
-
-
- vehicle = patches.Polygon(
- rotated_corners, closed=True, fill=True, color=vehicle_color, alpha=0.5
- )
- ax.add_patch(vehicle)
- plt.title(f'Time: {current_time:.2f}s')
- ani = FuncAnimation(fig, update, frames=len(grouped_car_data.groups), repeat=True, interval=50)
- plt.show()
|