-
Hi there, I'm excited to explore the new CSVSink and JSONSink features introduced in supervision-0.19.0! I've been experimenting with these features for the past few days, and they make post-processing incredibly straightforward. In the release video (https://github.com/roboflow/supervision/releases/tag/0.19.0), I noticed a really cool 3D road visualization effect "traffic_csv_2.mp4". However, I haven't been able to replicate that dynamic effect using any of the visualization methods I've tried so far. Could you please provide some guidance on how to achieve a similar 3D road visualization effect from stored .csv files using supervision-0.19.0? I'd love to learn more about the techniques and code involved in creating such an impressive visualization. And this is the very naive way I'm using now for visualize the trajectory import matplotlib
matplotlib.use('Agg')
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
import supervision as sv
def plot_trajectory(df, tracker_id=None):
# Create a white board with the same resolution as the video
fig, ax = plt.subplots(figsize=(width/100, height/100)) # Divide by 100 to make the figure smaller
ax.set_xlim([0, width])
ax.set_ylim([0, height])
ax.set_facecolor('white')
if tracker_id is None:
# Plot the center points of all bounding boxes on the white board
for id in df['tracker_id'].unique():
df_id = df[df['tracker_id'] == id]
ax.plot(df_id['x_center'], df_id['y_center'], marker='o')
else:
# Plot the center points of the bounding boxes of the specified tracker_id on the white board
df_id = df[df['tracker_id'] == tracker_id]
ax.plot(df_id['x_center'], df_id['y_center'], marker='o')
plt.gca().invert_yaxis() # Invert y axis as origin is top-left in image
plt.savefig(f'trajectory_{tracker_id if tracker_id else "all"}.png') # Save the figure to a file
video_info = sv.VideoInfo.from_video_path(video_path='city.mp4')
# (1920, 1080)
width, height = video_info.resolution_wh
# Load the output.csv file
df = pd.read_csv('output.csv')
# Calculate the center of each bounding box
df['x_center'] = (df['x_min'] + df['x_max']) / 2
df['y_center'] = (df['y_min'] + df['y_max']) / 2
# Call the function with the desired tracker_id
plot_trajectory(df, tracker_id=14) # Desired tracker_id
# Call the function without specifying a tracker_id to plot all tracking ids
plot_trajectory(df) Thank you in advance for any insights or resources you can share! I'm really excited to take my road detection project to the next level with this visualization capability. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 2 replies
-
Hi @JYe9 👋🏻 That's the Colab I used: https://colab.research.google.com/drive/11FUFklwHMWaNz43CXLT6S2PIYAtUfhoe?usp=sharing I hope it will be useful ;) |
Beta Was this translation helpful? Give feedback.
Hi @JYe9 👋🏻 That's the Colab I used: https://colab.research.google.com/drive/11FUFklwHMWaNz43CXLT6S2PIYAtUfhoe?usp=sharing I hope it will be useful ;)