From 22483cb53a508bc2d4ef5066b721067f37d6c7b4 Mon Sep 17 00:00:00 2001 From: "Lihi Gur-Arie, PhD" <63953488+Lihi-Gur-Arie@users.noreply.github.com> Date: Thu, 28 Sep 2023 07:34:31 +0300 Subject: [PATCH] fixed a bug (#181) Co-authored-by: lihi --- motmetrics/mot.py | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/motmetrics/mot.py b/motmetrics/mot.py index 4eeed9b..b04fde5 100644 --- a/motmetrics/mot.py +++ b/motmetrics/mot.py @@ -257,9 +257,19 @@ def update(self, oids, hids, dists, frameid=None, vf=''): o = oids[i] h = hids[j] - is_switch = (o in self.m and - self.m[o] != h and - abs(frameid - self.last_occurrence[o]) <= self.max_switch_time) + ###################################################################### + # todo - fixed a bug: + # is_switch = (o in self.m and + # self.m[o] != h and + # abs(frameid - self.last_occurrence[o]) <= self.max_switch_time) + switch_condition = ( + o in self.m and + self.m[o] != h and + o in self.last_occurrence and # Ensure the object ID 'o' is initialized in last_occurrence + abs(frameid - self.last_occurrence[o]) <= self.max_switch_time + ) + is_switch = switch_condition + ###################################################################### cat1 = 'SWITCH' if is_switch else 'MATCH' if cat1 == 'SWITCH': if h not in self.hypHistory: