File size: 776 Bytes
9e14838
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
from .sort import Sort
import numpy as np


def get_detections(faces):
    detections = []
    for face in faces:
        x1, y1, x2, y2 = face[0]
        detections.append((x1, y1, x2, y2, face[-1]))
    return np.array(detections)


def get_tracks(detect_results):
    tracks = {}
    mot_tracker = Sort()
    for faces in detect_results:
        detections = get_detections(faces)
        track_bbs_ids = mot_tracker.update(detections)
        for track in track_bbs_ids:  # 单独框出每一张人脸
            id = int(track[-1])
            box = track[:4]
            if id in tracks:
                tracks[id].append(box)
            else:
                tracks[id] = [box]

    return [track for id, track in tracks.items() if len(track) == len(detect_results)]