| 4 | |
| 5 | |
| 6 | def write_results(filename, results_dict: Dict, data_type: str): |
| 7 | if not filename: |
| 8 | return |
| 9 | path = os.path.dirname(filename) |
| 10 | if not os.path.exists(path): |
| 11 | os.makedirs(path) |
| 12 | |
| 13 | if data_type in ('mot', 'mcmot', 'lab'): |
| 14 | save_format = '{frame},{id},{x1},{y1},{w},{h},1,-1,-1,-1\n' |
| 15 | elif data_type == 'kitti': |
| 16 | save_format = '{frame} {id} pedestrian -1 -1 -10 {x1} {y1} {x2} {y2} -1 -1 -1 -1000 -1000 -1000 -10 {score}\n' |
| 17 | else: |
| 18 | raise ValueError(data_type) |
| 19 | |
| 20 | with open(filename, 'w') as f: |
| 21 | for frame_id, frame_data in results_dict.items(): |
| 22 | if data_type == 'kitti': |
| 23 | frame_id -= 1 |
| 24 | for tlwh, track_id in frame_data: |
| 25 | if track_id < 0: |
| 26 | continue |
| 27 | x1, y1, w, h = tlwh |
| 28 | x2, y2 = x1 + w, y1 + h |
| 29 | line = save_format.format(frame=frame_id, id=track_id, x1=x1, y1=y1, x2=x2, y2=y2, w=w, h=h, score=1.0) |
| 30 | f.write(line) |
| 31 | |
| 32 | |
| 33 | def read_results(filename, data_type: str, is_gt=False, is_ignore=False): |