예제 #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)))
예제 #2
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