Params: dets - a numpy array of detections in the format [[x1,y1,x2,y2,score],[x1,y1,x2,y2,score],...] Requires: this method must be called once for each frame even with empty detections (use np.empty((0, 5)) for frames without detections). Returns the a similar array, where the l
(self, dets=np.empty((0, 5)))
| 208 | self.frame_count = 0 |
| 209 | |
| 210 | def update(self, dets=np.empty((0, 5))): |
| 211 | """ |
| 212 | Params: |
| 213 | dets - a numpy array of detections in the format [[x1,y1,x2,y2,score],[x1,y1,x2,y2,score],...] |
| 214 | Requires: this method must be called once for each frame even with empty detections (use np.empty((0, 5)) for frames without detections). |
| 215 | Returns the a similar array, where the last column is the object ID. |
| 216 | |
| 217 | NOTE: The number of objects returned may differ from the number of detections provided. |
| 218 | """ |
| 219 | self.frame_count += 1 |
| 220 | # get predicted locations from existing trackers. |
| 221 | trks = np.zeros((len(self.trackers), 5)) |
| 222 | to_del = [] |
| 223 | ret = [] |
| 224 | for t, trk in enumerate(trks): |
| 225 | pos = self.trackers[t].predict()[0] |
| 226 | trk[:] = [pos[0], pos[1], pos[2], pos[3], 0] |
| 227 | if np.any(np.isnan(pos)): |
| 228 | to_del.append(t) |
| 229 | trks = np.ma.compress_rows(np.ma.masked_invalid(trks)) |
| 230 | for t in reversed(to_del): |
| 231 | self.trackers.pop(t) |
| 232 | matched, unmatched_dets, unmatched_trks = associate_detections_to_trackers(dets,trks, self.iou_threshold) |
| 233 | |
| 234 | # update matched trackers with assigned detections |
| 235 | for m in matched: |
| 236 | self.trackers[m[1]].update(dets[m[0], :]) |
| 237 | |
| 238 | # create and initialise new trackers for unmatched detections |
| 239 | for i in unmatched_dets: |
| 240 | trk = KalmanBoxTracker(dets[i,:]) |
| 241 | self.trackers.append(trk) |
| 242 | i = len(self.trackers) |
| 243 | for trk in reversed(self.trackers): |
| 244 | d = trk.get_state()[0] |
| 245 | if (trk.time_since_update < 1) and (trk.hit_streak >= self.min_hits or self.frame_count <= self.min_hits): |
| 246 | ret.append(np.concatenate((d,[trk.id+1])).reshape(1,-1)) # +1 as MOT benchmark requires positive |
| 247 | i -= 1 |
| 248 | # remove dead tracklet |
| 249 | if(trk.time_since_update > self.max_age): |
| 250 | self.trackers.pop(i) |
| 251 | if(len(ret)>0): |
| 252 | return np.concatenate(ret) |
| 253 | return np.empty((0,5)) |
| 254 | |
| 255 | def parse_args(): |
| 256 | """Parse input arguments.""" |
no test coverage detected