Skip to content

Commit

Permalink
Add an initialization delay for the clusters
Browse files Browse the repository at this point in the history
  • Loading branch information
Agustín Castro authored and Agustín Castro committed Feb 28, 2024
1 parent 3a2c9e9 commit 34b14ec
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 36 deletions.
14 changes: 14 additions & 0 deletions demos/multi_camera/demo.py
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,18 @@ def run():
default=20,
help="Min detections needed to start the tracked object",
)
parser.add_argument(
"--clusterizer-initialization-delay",
type=float,
default=6,
help="Minimum age of a cluster (or it's objects) to be returned",
)
parser.add_argument(
"--filter-by-objects-age",
type=bool,
default=False,
help="Filter cluster by their objects age, instead of the clusters age.",
)
parser.add_argument(
"--hit-counter-max",
type=int,
Expand Down Expand Up @@ -450,6 +462,8 @@ def normalized_foot_distance(tracker1, tracker2):
max_votes_grow=args.max_votes_grow,
max_votes_split=args.max_votes_grow,
memory=args.memory,
initialization_delay=args.clusterizer_initialization_delay,
filter_by_objects_age=args.filter_by_objects_age,
)

while True:
Expand Down
36 changes: 1 addition & 35 deletions norfair/common_reference_ui.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,40 +11,6 @@
from norfair import Video
from norfair.camera_motion import HomographyTransformationGetter, TransformationGetter

transformation = None

window = None

button_finish = None

reference_point_canvas = None
footage_point_canvas = None

canvas_reference = None
canvas_footage = None

reference_original_size = None
reference_canvas_size = None
footage_original_size = None
footage_canvas_size = None

footage_point = None
reference_point = None

skipper = None

points = None
points_sampled = None

mode_annotate = None

frame_options_annotations = None
handling_mark_functions = None
handle_mark_annotation = None

global button_says_ignore
global button_ignore


def resize_image(image, desired_width=None, desired_height=None):
aspect_ratio = image.height / image.width
Expand Down Expand Up @@ -281,7 +247,7 @@ def handle_finish():
for info in skipper.values():
if info["video"] is not None:
info["video"].video_capture.release()
cv2.destroyAllWindows()
cv2.destroyAllWindows()
return transformation
else:
print("Can't leave without estimating the transformation.")
Expand Down
35 changes: 34 additions & 1 deletion norfair/multi_camera.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,8 @@ def __init__(
max_votes_grow: int = 5,
max_votes_split: int = 5,
memory: int = 3,
initialization_delay: int = 4,
filter_by_objects_age: bool = False,
):
"""
Associate trackers from different cameras/videos.
Expand Down Expand Up @@ -130,6 +132,12 @@ def __init__(
self.max_votes_grow = max_votes_grow
self.max_votes_split = max_votes_split

# I will give the trackers at least enough time to merge their cluster with another
self.initialization_delay = initialization_delay + max_votes_grow
self.filter_by_objects_age = filter_by_objects_age

self.id_to_ages = {}

def update(self, trackers_by_camera):
# trackers_by_camera = [list(tracked_objects_camera_0), list(tracked_objects_camera_1),...]

Expand Down Expand Up @@ -649,4 +657,29 @@ def update(self, trackers_by_camera):
cluster for cluster in self.clusters if len(cluster) > 0
]

return self.clusters
if self.filter_by_objects_age:
return [
cluster
for cluster in self.clusters
if any(
[
obj.age - obj.initialization_delay > self.initialization_delay
for obj in cluster.tracked_objects.values()
]
)
]
else:
id_to_ages = {}
for cluster in self.clusters:
if cluster.id in self.id_to_ages.keys():
id_to_ages[cluster.id] = self.id_to_ages[cluster.id] + 1
else:
id_to_ages[cluster.id] = 0

self.id_to_ages = id_to_ages

return [
cluster
for cluster in self.clusters
if id_to_ages[cluster.id] > self.initialization_delay
]

0 comments on commit 34b14ec

Please sign in to comment.