Ejemplo n.º 1
0
    def get_pairwise_vector(self,
                            video_name,
                            I1,
                            I2,
                            frame1,
                            frame2,
                            bb1,
                            bb2,
                            conf1,
                            conf2,
                            i1=None,
                            i2=None):
        if i1 is None:
            i1 = get_element(I1, bb1, (64, 64), force_uint=True)
        if i2 is None:
            i2 = get_element(I2, bb2, (64, 64), force_uint=True)

        st_cost = st.calculate(bb1, bb2)
        dm_cost = self.dm.calculate_cost(video_name, frame1, bb1, frame2, bb2)
        reid_cost = self.stacknet.predict(i1, i2)
        min_conf = min(conf1, conf2)

        return (1,st_cost , dm_cost , reid_cost , min_conf , \
                st_cost**2,st_cost * dm_cost,st_cost * reid_cost, st_cost * min_conf, \
                dm_cost**2,dm_cost * reid_cost ,dm_cost * min_conf , \
                reid_cost**2,reid_cost * min_conf , \
                min_conf**2)
Ejemplo n.º 2
0
    def __init__(self, Dt, X, H=64, W=64):
        """ctor
            Dt: {np.array} detections for the video
                -> [(frame, x, y, w, h, score), ...]

            X: {np.array} (n, w, h, 3) video of the detections
        """
        n, m = Dt.shape
        assert m == 6

        self.Im = np.zeros((n, H, W, 3), 'uint8')
        self.AABBs = np.zeros((n, 4), 'float32')
        IDS_IN_FRAME = [None] * (n + 1)  # frames start at 1 and not at 0
        self.Scores = [0] * n
        self.Frames = np.array([0] * n)

        for i, (frame, x, y, w, h, score) in enumerate(Dt):
            frame = int(frame)
            im = get_element(X[frame-1], (x,y,w,h), (W, H), True)
            self.Im[i] = im
            self.AABBs[i] = np.array([x,y,w,h])
            self.Scores[i] = score
            self.Frames[i] = frame

            if IDS_IN_FRAME[frame] is None:
                IDS_IN_FRAME[frame] = []
            IDS_IN_FRAME[frame].append(i)

        self.ids_in_frame = IDS_IN_FRAME
        self.Scores = np.array(self.Scores)
        self.LAST_FRAME = X.shape[0]
Dt = vd.get_n_first_frames(100)

n, _ = Dt.shape
W, H = 64, 64

print("Dt", Dt.shape)
print("\n")

Im = np.zeros((n, H, W, 3), 'uint8')

IDS_IN_FRAME = [None] * (X.shape[0] + 1)
LAST_FRAME = X.shape[0]

for i, (frame, x, y, w, h, _) in enumerate(Dt):
    frame_i = int(frame)
    im = get_element(X[frame_i - 1], (x, y, w, h), (W, H), True)
    Im[i] = im

    if IDS_IN_FRAME[frame_i] is None:
        IDS_IN_FRAME[frame_i] = []
    IDS_IN_FRAME[frame_i].append(i)

ALL_PAIRS = []
for frame_i, ids_in_frame in enumerate(IDS_IN_FRAME):
    if ids_in_frame is None:
        continue

    for i in ids_in_frame:
        for j in ids_in_frame:
            if i != j:
                ALL_PAIRS.append((i, j))