-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
1a7bfc1
commit 24cb5f9
Showing
2 changed files
with
50 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import csv | ||
|
||
def save_video_tracking_data(tracks, file_name): | ||
"""Save tracking data to a CSV file.""" | ||
fieldnames = tracks.keys() | ||
|
||
# Write the dictionary to the CSV file in append mode | ||
with open(file_name, 'a', newline='') as csvfile: | ||
writer = csv.DictWriter(csvfile, fieldnames=fieldnames) | ||
|
||
# Check if the file is empty (i.e., if it needs a header row) | ||
# If the file is empty, write the header row | ||
if csvfile.tell() == 0: | ||
writer.writeheader() | ||
|
||
# Write each row of the dictionary to the CSV file | ||
for i in range(len(tracks['frame'])): | ||
row = {field: tracks[field][i] for field in fieldnames} | ||
writer.writerow(row) |