from pathlib import Path
from typing import Dict, List, Tuple, Union
import csv
def read_detections(
file_path: Union[str, Path]
) -> Dict[int, List[Tuple[float, float, float, float, float]]]:
frame_detections = {}
with open(file_path, 'r') as file_obj:
for row in csv.reader(file_obj):
frame_num = int(row[0])
if frame_num not in frame_detections:
frame_detections[frame_num] = []
frame_detections[frame_num].append(tuple(map(float, row[2:7])))
return frame_detections
def write_csv(file_path: Union[str, Path], rows: List[Tuple]):
with open(file_path, mode="w", newline="") as res_file:
csv_writer = csv.writer(res_file, lineterminator="\n")
csv_writer.writerows(rows)