box select in a track and feat simi modify in tracker

This commit is contained in:
王庆刚
2025-01-14 19:00:59 +08:00
parent 744fb7b7b2
commit bfe7bc0fd5
11 changed files with 157 additions and 22 deletions

View File

@ -22,6 +22,37 @@ class MoveState:
FreeMove = 3
Unknown = -1
def bbox_ioa(box1, box2, iou=False, eps=1e-7):
"""
Calculate the intersection over box2 area given box1 and box2. Boxes are in x1y1x2y2 format.
Args:
box1 (np.array): A numpy array of shape (n, 4) representing n bounding boxes.
box2 (np.array): A numpy array of shape (m, 4) representing m bounding boxes.
iou (bool): Calculate the standard iou if True else return inter_area/box2_area.
eps (float, optional): A small value to avoid division by zero. Defaults to 1e-7.
Returns:
(np.array): A numpy array of shape (n, m) representing the intersection over box2 area.
"""
# Get the coordinates of bounding boxes
b1_x1, b1_y1, b1_x2, b1_y2 = box1.T
b2_x1, b2_y1, b2_x2, b2_y2 = box2.T
# Intersection area
inter_area = (np.minimum(b1_x2[:, None], b2_x2) - np.maximum(b1_x1[:, None], b2_x1)).clip(0) * \
(np.minimum(b1_y2[:, None], b2_y2) - np.maximum(b1_y1[:, None], b2_y1)).clip(0)
# box2 area
area = (b2_x2 - b2_x1) * (b2_y2 - b2_y1)
if iou:
box1_area = (b1_x2 - b1_x1) * (b1_y2 - b1_y1)
area = area + box1_area[:, None] - inter_area
# Intersection over box2 area
return inter_area / (area + eps)
class ShoppingCart:
def __init__(self, bboxes):
@ -90,6 +121,7 @@ class Track:
self.boxes = boxes
self.features = features
self.slt_boxes = self.select_boxes()
self.tid = int(boxes[0, 4])
self.cls = int(boxes[0, 6])
@ -138,6 +170,43 @@ class Track:
self.HAND_STATIC_THRESH = 100
if self.cls == 0:
self.extract_hand_features()
def select_boxes(self):
slt_boxes = []
idx = np.argsort(self.boxes[:, 7])
boxes = self.boxes[idx]
features = self.features[idx]
for i in range(len(boxes)):
simi = None
box, tid, fid, bid = boxes[i, :4], int(boxes[i, 4]), int(boxes[i, 7]), int(boxes[i, 8])
if i == 0:
slt_boxes.append(boxes[i, :])
continue
if len(boxes)!=len(features):
print("check!")
continue
box0, tid0, fid0, bid0 = boxes[i-1, :4], int(boxes[i-1, 4]), int(boxes[i-1, 7]), int(boxes[i-1, 8])
# 当前 box 和轨迹上一个 box 的iou
iou = bbox_ioa(box[None, :], box0[None, :])
# 当前 box 和轨迹上一个 box 的 feat similarity
feat0 = features[i, :][None, :]
feat1 = features[i-1, :][None, :]
simi = 1 - np.maximum(0.0, cdist(feat0, feat1, "cosine"))[0][0]
if iou > 0.85 and simi>0.85:
continue
slt_boxes.append(boxes[i, :])
return np.array(slt_boxes)
def compute_cornpoints(self):
@ -415,6 +484,8 @@ class doTracks:
self.DownWard = [] # subset of self.Residual
self.UpWard = [] # subset of self.Residual
self.FreeMove = [] # subset of self.Residual
def array2list(self):