a b/darkflow/utils/box.py
1
import numpy as np
2
3
4
class BoundBox:
5
    def __init__(self, classes):
6
        self.x, self.y = float(), float()
7
        self.w, self.h = float(), float()
8
        self.c = float()
9
        self.class_num = classes
10
        self.probs = np.zeros((classes,))
11
12
13
def overlap(x1, w1, x2, w2):
14
    l1 = x1 - w1 / 2.;
15
    l2 = x2 - w2 / 2.;
16
    left = max(l1, l2)
17
    r1 = x1 + w1 / 2.;
18
    r2 = x2 + w2 / 2.;
19
    right = min(r1, r2)
20
    return right - left;
21
22
23
def box_intersection(a, b):
24
    w = overlap(a.x, a.w, b.x, b.w);
25
    h = overlap(a.y, a.h, b.y, b.h);
26
    if w < 0 or h < 0: return 0;
27
    area = w * h;
28
    return area;
29
30
31
def box_union(a, b):
32
    i = box_intersection(a, b);
33
    u = a.w * a.h + b.w * b.h - i;
34
    return u;
35
36
37
def box_iou(a, b):
38
    return box_intersection(a, b) / box_union(a, b);
39
40
41
def prob_compare(box):
42
    return box.probs[box.class_num]
43
44
45
def prob_compare2(boxa, boxb):
46
    if (boxa.pi < boxb.pi):
47
        return 1
48
    elif (boxa.pi == boxb.pi):
49
        return 0
50
    else:
51
        return -1