1717 MOT16 tracking demo
1818
1919 Usage:
20- python examples/mot16_challange.py --dataset_root ~/Downloads/MOT16 --seq_id 11
20+ python examples/mot16_challange.py --dataset_root= ~/Downloads/MOT16 --seq_id= 11
2121
2222 Note: this is just a demo, the script does not evaluate the tracking on MOT16 dataset.
23+ Also, since provided by MOT16 `predictions` do not represent (IMO) the current state
24+ of modern detectors, the demo utilizes ground truth + noise as input to the tracker;
25+ feel free to use `sel=det` to check the 'real' MOT16 predictions, but keep in mind that
26+ tracker is not optimized at all for such noisy predictions.
2327
2428"""
2529
@@ -37,6 +41,7 @@ def read_video_frame(directory, frame_idx):
3741
3842
3943def read_detections (path , drop_detection_prob : float = 0.0 , add_detection_noise : float = 0.0 ):
44+ """ parses and converts MOT16 benchmark annotations to known [xmin, ymin, xmax, ymax] format """
4045 path = os .path .expanduser (path )
4146 logger .debug ('reading detections from %s' % path )
4247 if not os .path .isfile (path ):
@@ -70,13 +75,15 @@ def get_miliseconds():
7075
7176def run (
7277 dataset_root : str ,
73- fps = 30 ,
78+ fps : float = 30.0 ,
7479 split : str = 'train' ,
75- seq_id = '04' ,
76- sel = 'gt' ,
80+ seq_id : str = '04' ,
81+ sel : str = 'gt' ,
7782 drop_detection_prob : float = 0.1 ,
7883 add_detection_noise : float = 5.0 ):
84+ """ parses detections, loads frames, runs tracking and visualizes the tracked objects """
7985
86+ dataset_root = os .path .expanduser (dataset_root )
8087 if not os .path .isdir (dataset_root ):
8188 logger .error ('%s does not exist' % dataset_root )
8289 exit (- 1 )
@@ -97,32 +104,43 @@ def run(
97104
98105 tracker = MultiObjectTracker (
99106 dt = 1 / fps , tracker_kwargs = {'max_staleness' : 15 },
100- model_spec = '2d_constant_acceleration+static_box_size' )
101-
102- # TODO cleanup
103- tracker .matching_fn .min_iou = 0.25
107+ model_spec = 'constant_acceleration_and_static_box_size_2d' ,
108+ matching_fn_kwargs = {'min_iou' : 0.25 })
104109
105110 # tracking loop
106111 while True :
107- frame_idx , detections = next (dets_gen )
112+ # read detections for a given frame
113+ try :
114+ frame_idx , detections = next (dets_gen )
115+ except Exception as e :
116+ logger .warning ('finished reading the sequence' )
117+ logger .trace (f'exception: { e } ' )
118+ break
119+
120+ # read the frame for a given index
108121 frame = read_video_frame (frames_dir , frame_idx )
109122 if frame is None :
110123 continue
111124
125+ # provide the MOT tracker with predicted detections
112126 t1 = get_miliseconds ()
113127 active_tracks = tracker .step (detections )
114128 ms_elapsed = get_miliseconds () - t1
115129 logger .debug ('step duration: %dms' % ms_elapsed )
116130
131+ # visualize predictions and tracklets
117132 for det in detections :
118133 draw_detection (frame , det )
119134
120135 for track in active_tracks :
121136 draw_track (frame , track )
122137
123138 cv2 .imshow ('preview' , frame )
139+
140+ # stop execution on q
124141 key = cv2 .waitKey (int (1000 / fps ))
125142 if key == ord ('q' ):
143+ logger .info ('early stopping' )
126144 break
127145
128146
0 commit comments