use iou instead of centroid

This commit is contained in:
Blake Blackshear 2022-02-05 08:29:01 -06:00
parent e627f4e935
commit dd1cf4d2ce

View File

@ -52,22 +52,21 @@ class ObjectTracker:
# returns False if the object has moved outside its previous position # returns False if the object has moved outside its previous position
def update_position(self, id, box): def update_position(self, id, box):
position = self.positions[id] position = self.positions[id]
position_box = (
position["xmin"],
position["ymin"],
position["xmax"],
position["ymax"],
)
xmin, ymin, xmax, ymax = box xmin, ymin, xmax, ymax = box
# get the centroid iou = intersection_over_union(position_box, box)
x = (xmax + xmin) / 2
y = (ymax + ymin) / 2
# if the centroid of this box is outside the computed bounding box # if the iou drops below the threshold
# assume the object has moved to a new position and reset the computed box # assume the object has moved to a new position and reset the computed box
# TODO: should this only happen if there are a few boxes? if iou < 0.6:
if ( self.positions[id] = {
x < position["xmin"]
or x > position["xmax"]
or y < position["ymin"]
or y > position["ymax"]
):
position = {
"xmins": [xmin], "xmins": [xmin],
"ymins": [ymin], "ymins": [ymin],
"xmaxs": [xmax], "xmaxs": [xmax],