银行 网站开发 干什么,国家信用企业信息系统,wordpress国外vps,宁夏网站备案目标
利用匈牙利算法对目标框和检测框进行关联 在这里我们对检测框和跟踪框进行匹配#xff0c;整个流程是遍历检测框和跟踪框#xff0c;并进行匹配#xff0c;匹配成功的将其保留#xff0c;未成功的将其删除。 def associate_detections_to_trackers(detections, track…目标
利用匈牙利算法对目标框和检测框进行关联 在这里我们对检测框和跟踪框进行匹配整个流程是遍历检测框和跟踪框并进行匹配匹配成功的将其保留未成功的将其删除。 def associate_detections_to_trackers(detections, trackers, iou_threshold0.3):将检测框bbox与卡尔曼滤波器的跟踪框进行关联匹配:param detections:检测框:param trackers:跟踪框即跟踪目标:param iou_threshold:IOU阈值:return:跟踪成功目标的矩阵matchs新增目标的矩阵unmatched_detections跟踪失败即离开画面的目标矩阵unmatched_trackers# 跟踪目标数量为0直接构造结果if (len(trackers) 0) or (len(detections) 0):return np.empty((0, 2), dtypeint), np.arange(len(detections)), np.empty((0, 5), dtypeint)# iou 不支持数组计算。逐个计算两两间的交并比调用 linear_assignment 进行匹配iou_matrix np.zeros((len(detections), len(trackers)), dtypenp.float32)# 遍历目标检测的bbox集合每个检测框的标识为dfor d, det in enumerate(detections):# 遍历跟踪框卡尔曼滤波器预测bbox集合每个跟踪框标识为tfor t, trk in enumerate(trackers):iou_matrix[d, t] iou(det, trk)# 通过匈牙利算法将跟踪框和检测框以[[d,t]...]的二维矩阵的形式存储在match_indices中result linear_sum_assignment(-iou_matrix)matched_indices np.array(list(zip(*result)))# 记录未匹配的检测框及跟踪框# 未匹配的检测框放入unmatched_detections中表示有新的目标进入画面要新增跟踪器跟踪目标unmatched_detections []for d, det in enumerate(detections):if d not in matched_indices[:, 0]:unmatched_detections.append(d)# 未匹配的跟踪框放入unmatched_trackers中表示目标离开之前的画面应删除对应的跟踪器unmatched_trackers []for t, trk in enumerate(trackers):if t not in matched_indices[:, 1]:unmatched_trackers.append(t)# 将匹配成功的跟踪框放入matches中matches []for m in matched_indices:# 过滤掉IOU低的匹配将其放入到unmatched_detections和unmatched_trackersif iou_matrix[m[0], m[1]] iou_threshold:unmatched_detections.append(m[0])unmatched_trackers.append(m[1])# 满足条件的以[[d,t]...]的形式放入matches中else:matches.append(m.reshape(1, 2))# 初始化matches,以np.array的形式返回if len(matches) 0:matches np.empty((0, 2), dtypeint)else:matches np.concatenate(matches, axis0)return matches, np.array(unmatched_detections), np.array(unmatched_trackers)