Repository navigation
Expand file tree
/
Copy pathrect.py
More file actions
38 lines (38 loc) · 1.58 KB
/
Copy pathrect.py
File metadata and controls
38 lines (38 loc) · 1.58 KB
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
29
30
31
32
33
34
35
36
37
38
class Rect(object):
def __init__(self, cx, cy, width, height, confidence):
self.cx = cx
self.cy = cy
self.width = width
self.height = height
self.confidence = confidence
self.true_confidence = confidence
def overlaps(self, other):
if abs(self.cx - other.cx) > (self.width + other.width) / 1.5:
return False
elif abs(self.cy - other.cy) > (self.height + other.height) / 2.0:
return False
else:
return True
def distance(self, other):
return sum(map(abs, [self.cx - other.cx, self.cy - other.cy,
self.width - other.width, self.height - other.height]))
def intersection(self, other):
left = max(self.cx - self.width/2., other.cx - other.width/2.)
right = min(self.cx + self.width/2., other.cx + other.width/2.)
width = max(right - left, 0)
top = max(self.cy - self.height/2., other.cy - other.height/2.)
bottom = min(self.cy + self.height/2., other.cy + other.height/2.)
height = max(bottom - top, 0)
return width * height
def area(self):
return self.height * self.width
def union(self, other):
return self.area() + other.area() - self.intersection(other)
def iou(self, other):
return self.intersection(other) / self.union(other)
def __eq__(self, other):
return (self.cx == other.cx and
self.cy == other.cy and
self.width == other.width and
self.height == other.height and
self.confidence == other.confidence)