From cb247f9726bbade344e8d846baa1952729f41c6f Mon Sep 17 00:00:00 2001 From: tgonjo Date: Thu, 5 Dec 2024 12:10:06 +0000 Subject: [PATCH] Included a coodinates export function (csv format) --- gradio_demo/app.py | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/gradio_demo/app.py b/gradio_demo/app.py index 5c6779c..701a609 100644 --- a/gradio_demo/app.py +++ b/gradio_demo/app.py @@ -17,6 +17,7 @@ from typing import List, Optional, Sequence, Tuple import numpy as np +import csv # Generate random colormaps for visualizing different points. @@ -400,7 +401,18 @@ def track( mediapy.write_video(video_file_path, painted_video, fps=video_fps) - return video_file_path + tracks_file_name = uuid.uuid4().hex + "_tracks.csv" + tracks_file_path = os.path.join(video_path, tracks_file_name) + + # Save `tracks` as CSV + with open(tracks_file_path, mode='w', newline='') as csv_file: + csv_writer = csv.writer(csv_file) + csv_writer.writerow(["Point_Index", "Frame", "X", "Y"]) # Header + for frame_index, frame_tracks in enumerate(tracks): + for point_index, (x, y) in enumerate(frame_tracks): + csv_writer.writerow([frame_index, point_index, x, y]) + + return (video_file_path, tracks_file_path) with gr.Blocks() as demo: @@ -593,6 +605,8 @@ def track( queue = False ) + download_csv = gr.File(label="Download Tracked Points (CSV)") + track_button.click( fn = track, @@ -605,10 +619,10 @@ def track( query_count, ], outputs = [ - output_video, + output_video,download_csv ], queue = True, ) -demo.launch(show_api=False, show_error=True, debug=True, share=True) \ No newline at end of file +demo.launch(show_api=False, show_error=True, debug=True, share=True)