From d871031bd5538fd637de2f61be13d8356adaa525 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Agust=C3=ADn=20Castro?= Date: Fri, 22 Mar 2024 15:10:15 -0300 Subject: [PATCH] Fix bug of Nonetype cluster referenced when splitting --- demos/multi_camera/src/demo.py | 34 ++++++++++++++++++---------------- norfair/multi_camera.py | 4 +++- 2 files changed, 21 insertions(+), 17 deletions(-) diff --git a/demos/multi_camera/src/demo.py b/demos/multi_camera/src/demo.py index 8c05eb6c..4c7e8c1c 100644 --- a/demos/multi_camera/src/demo.py +++ b/demos/multi_camera/src/demo.py @@ -124,6 +124,22 @@ def draw_feet( return frame +def get_embedding(bbox, frame): + t_shirt_bbox_x = 0.7 * bbox[:, 0] + 0.3 * bbox[::-1, 0] + top = np.min(bbox[:, 1]) + bottom = np.max(bbox[:, 1]) + t_shirt_bbox_y = np.array([top * 0.9 + bottom * 0.1, top * 0.5 + bottom * 0.5]) + + bbox[:, 0] = t_shirt_bbox_x + bbox[:, 1] = t_shirt_bbox_y + + cut = get_cutout(bbox, frame) + if cut.shape[0] > 0 and cut.shape[1] > 0: + return get_hist(cut) + else: + return None + + def draw_cluster_bboxes( images, clusters, @@ -199,21 +215,7 @@ def yolo_detections_to_norfair_detections(yolo_detections, frame): boxes.append(bbox) points = bbox.copy() scores = np.array([detection_as_xyxy[4], detection_as_xyxy[4]]) - - # get embedding - t_shirt_bbox_x = 0.7 * bbox[:, 0] + 0.3 * bbox[::-1, 0] - top = np.min(bbox[:, 1]) - bottom = np.max(bbox[:, 1]) - t_shirt_bbox_y = np.array([top * 0.7 + bottom * 0.3, top * 0.4 + bottom * 0.6]) - - bbox[:, 0] = t_shirt_bbox_x - bbox[:, 1] = t_shirt_bbox_y - - cut = get_cutout(bbox, frame) - if cut.shape[0] > 0 and cut.shape[1] > 0: - embedding = get_hist(cut) - else: - embedding = None + embedding = get_embedding(bbox, frame) norfair_detections.append( Detection( @@ -292,7 +294,7 @@ def run(): parser.add_argument( "--reid-embedding-correlation-threshold", type=float, - default=0.5, + default=0.3, help="Threshold for embedding match during a reid phase after object has been lost. (The 1-correlation distance we use is bounded in [0, 2])", ) parser.add_argument( diff --git a/norfair/multi_camera.py b/norfair/multi_camera.py index fa2b0480..629a1ea1 100644 --- a/norfair/multi_camera.py +++ b/norfair/multi_camera.py @@ -471,6 +471,8 @@ def conditionally_update_which_id_keeper( keep_id_criteria, ): + if additional_cluster_number_keeping_old_id is None: + return True # keep the id by the age or by the hit_counter if the current cluster is promising if not tracked_object.live_points.any(): # if this cluster hasn't matched recently, cluster is not promising @@ -702,7 +704,7 @@ def update(self, trackers_by_camera): # create the aditional clusters additional_clusters = [] - additional_cluster_number_keeping_old_id = 0 + additional_cluster_number_keeping_old_id = None greatest_hit_counter = -1 oldest_age = -1 for current_cluster_number, tracked_ids in enumerate(