-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSortableBBox.py
More file actions
49 lines (33 loc) · 1.49 KB
/
SortableBBox.py
File metadata and controls
49 lines (33 loc) · 1.49 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
39
40
41
42
43
44
45
46
47
48
49
from tesseract_reader.bbox.bbox import BBox
class SortableBBox(BBox):
def __init__(self, x_top_left: int, y_top_left: int, width: int, height: int) -> None:
super().__init__(x_top_left, y_top_left, width, height)
@staticmethod
def converter(bbox: 'BBox'):
x = bbox.x_top_left
y = bbox.y_top_left
w = bbox.width
h = bbox.height
return SortableBBox(x, y, w, h)
@property
def eps(self, bbox):
eps = max(self.y_bottom_right - self.y_top_left, bbox.y_bottom_right - bbox.y_top_left)
return eps
def __gt__(self, bbox: 'BBox'):
eps = self.eps(bbox)
if self.y_top_left> bbox.y_top_left + eps:
return True
elif abs(bbox.y_top_left - self.y_top_left) < eps and self.x_top_left < bbox.x_top_left:
return True
return False
def __lt__(self, bbox: 'BBox'):
eps = max(self.y_bottom_right - self.y_top_left, bbox.y_bottom_right - bbox.y_top_left)
if self.y_top_left + eps < bbox.y_top_left:
return True
elif abs(bbox.y_top_left - self.y_top_left) < eps and bbox.x_top_left > self.x_top_left:
return True
return False
def point_is_in_bbox(self, point : list) -> bool:
x = point[0]
y = point[1]
return (x >= self.x_top_left and x <= self.x_bottom_right and y >= self.y_top_left and y <= self.y_bottom_right)