| 143 | |
| 144 | |
| 145 | class BYTETracker(object): |
| 146 | def __init__(self, args, frame_rate=30): |
| 147 | self.tracked_stracks = [] # type: list[STrack] |
| 148 | self.lost_stracks = [] # type: list[STrack] |
| 149 | self.removed_stracks = [] # type: list[STrack] |
| 150 | |
| 151 | self.frame_id = 0 |
| 152 | self.args = args |
| 153 | #self.det_thresh = args.track_thresh |
| 154 | self.det_thresh = args.track_thresh + 0.1 |
| 155 | self.buffer_size = int(frame_rate / 30.0 * 30) |
| 156 | self.max_time_lost = self.buffer_size |
| 157 | self.max_per_image = args.num_queries |
| 158 | self.kalman_filter = KalmanFilter() |
| 159 | |
| 160 | def update(self, output_results): |
| 161 | self.frame_id += 1 |
| 162 | activated_starcks = [] |
| 163 | refind_stracks = [] |
| 164 | lost_stracks = [] |
| 165 | removed_stracks = [] |
| 166 | |
| 167 | scores = output_results["scores"].cpu().numpy() |
| 168 | classes = output_results["labels"].cpu().numpy() |
| 169 | bboxes = output_results["boxes"].cpu().numpy() # x1y1x2y2 |
| 170 | |
| 171 | remain_inds = scores > self.args.track_thresh |
| 172 | inds_low = scores > 0.2 |
| 173 | inds_high = scores < self.args.track_thresh |
| 174 | inds_second = np.logical_and(inds_low, inds_high) |
| 175 | dets_second = bboxes[inds_second] |
| 176 | dets = bboxes[remain_inds] |
| 177 | scores_keep = scores[remain_inds] |
| 178 | scores_second = scores[inds_second] |
| 179 | |
| 180 | # vis |
| 181 | ''' |
| 182 | for i in range(0, dets.shape[0]): |
| 183 | bbox = dets[i][0:4] |
| 184 | cv2.rectangle(img0, (bbox[0], bbox[1]), |
| 185 | (bbox[2], bbox[3]), |
| 186 | (0, 255, 0), 2) |
| 187 | cv2.imshow('dets', img0) |
| 188 | cv2.waitKey(0) |
| 189 | id0 = id0-1 |
| 190 | ''' |
| 191 | |
| 192 | if len(dets) > 0: |
| 193 | '''Detections''' |
| 194 | detections = [STrack(STrack.tlbr_to_tlwh(tlbr), s, 30) for |
| 195 | (tlbr, s) in zip(dets, scores_keep)] |
| 196 | else: |
| 197 | detections = [] |
| 198 | |
| 199 | ''' Add newly detected tracklets to tracked_stracks''' |
| 200 | unconfirmed = [] |
| 201 | tracked_stracks = [] # type: list[STrack] |
| 202 | for track in self.tracked_stracks: |
no outgoing calls
no test coverage detected