Exemple #1
0
def test_dets():
    a = Det(101.3, 413.5, 67.2, 201.1)
    assert (a.cx == approx(101.3 + 67.2 / 2))
    assert (a.cy == approx(413.5 + 201.1 / 2))
    assert (a.x1 == approx(101.3))
    assert (a.y1 == approx(413.5))
    assert (a.w == approx(67.2))
    assert (a.h == approx(201.1))
    assert (a.x2 == approx(101.3 + 67.2))
    assert (a.y2 == approx(413.5 + 201.1))
    assert (a.area() == approx(67.2 * 201.1))
    a.cx += 1
    assert (a.x1 == approx(101.3 + 1))
    assert (a.x2 == approx(101.3 + 67.2 + 1))
    a.y2 += 2
    assert (a.y1 == approx(413.5))
    assert (a.cy == approx(413.5 + 201.1 / 2 + 1))
    b = Det(94.5, 510.1, 70.9, 203.7)
    assert (a.intersection(b) == approx(
        (94.5 + 70.9 - 101.3 - 1) * (413.5 + 201.1 + 2 - 510.1)))
    assert (a.iou(b) == approx(
        a.intersection(b) / (67.2 * 203.1 + 70.9 * 203.7 - a.intersection(b))))
    a.cx -= 150
    assert (a._trim(sz=(1920, 1080), toInt=False).x1 == approx(0))
    assert (a._trim(sz=(1920, 1080), toInt=False).cx == approx(
        (101.3 + 1 + 67.2 - 150) / 2.))
    assert (a._trim(sz=(1920, 1080), toInt=True).cx == approx(
        int((101.3 + 1 + 67.2 - 150) / 2))
            or a._trim(sz=(1920, 1080), toInt=True).cx == approx(
                (int(101.3 + 1 + 67.2 - 150) / 2)))
Exemple #2
0
 def get_gt_sim(self, framedata):
     assert self._current_gt is not None
     gt_dets = {d.uid: d for d in self._current_gt}
     sims = []
     for t in self.tracklets:
         sims.append([])
         for i in range(len(framedata['dets'])):
             if t.gt_id not in gt_dets:
                 sims[-1].append(0)
             else:
                 gdet = gt_dets[t.gt_id]
                 x1, y1, x2, y2 = map(float, framedata['dets'][i])
                 ddet = Det(x1, y1, x2 - x1, y2 - y1)
                 iou = ddet.iou(gdet)
                 if iou > 0.5:
                     sims[-1].append(iou + (1 - t.det.uid / self.idc) / 100)
                 else:
                     sims[-1].append(0)
     return np.array(sims, dtype=np.float32)
Exemple #3
0
def test_time1():
    a = Det(101.3, 413.5, 67.2, 201.1)
    assert (a.cx == approx(101.3 + 67.2 / 2))
    assert (a.cy == approx(413.5 + 201.1 / 2))
    assert (a.x1 == approx(101.3))
    assert (a.y1 == approx(413.5))
    assert (a.w == approx(67.2))
    assert (a.h == approx(201.1))
    assert (a.x2 == approx(101.3 + 67.2))
    assert (a.y2 == approx(413.5 + 201.1))
    assert (a.area() == approx(67.2 * 201.1))
    a.cx += 1
    assert (a.x1 == approx(101.3 + 1))
    assert (a.x2 == approx(101.3 + 67.2 + 1))
    a.y2 += 2
    assert (a.y1 == approx(413.5))
    assert (a.cy == approx(413.5 + 201.1 / 2 + 1))
    b = Det(94.5, 510.1, 70.9, 203.7)
    assert (a.intersection(b) == approx(
        (94.5 + 70.9 - 101.3 - 1) * (413.5 + 201.1 + 2 - 510.1)))
    assert (a.iou(b) == approx(
        a.intersection(b) / (67.2 * 203.1 + 70.9 * 203.7 - a.intersection(b))))
    c = 0.
    be = time.time()
    a_ = [a] * 5000000
    b_ = [b] * 5000000
    for i in range(5000000):
        c += a_[i].iou(b_[i])
    en = time.time()
    t1 = en - be
    # print(t1)
    # assert(t1 < 2)

    c = 0.
    be = time.time()
    for i in range(500000):
        a._trim(sz=(150, 150))
    en = time.time()
    t2 = en - be