-
Notifications
You must be signed in to change notification settings - Fork 3
/
data.py
78 lines (63 loc) · 1.8 KB
/
data.py
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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
class TrafficSignal:
def __init__(self, x, y, w, h, color_index, shape_index):
self.x = x
self.y = y
self.w = w
self.h = h
self.color_index = color_index
self.shape_index = shape_index
def __str__(self):
return f'box: [{self.x}, {self.y}, {self.w}, {self.h}] color: {self.color} shape: {self.shape}'
@property
def color(self):
if self.color_index == 0:
return 'red'
if self.color_index == 1:
return 'green'
if self.color_index == 2:
return 'yellow'
@property
def shape(self):
if self.shape_index == 0:
return 'full'
if self.shape_index == 1:
return 'left'
if self.shape_index == 2:
return 'right'
if self.shape_index == 3:
return 'straight'
@property
def center_x(self):
return self.x + (self.w >> 1)
@property
def center_y(self):
return self.y + (self.h >> 1)
@property
def x1(self):
return self.x
@property
def y1(self):
return self.y
@property
def x2(self):
return self.x + self.w
@property
def y2(self):
return self.y + self.h
@staticmethod
def from_bbox(bbox, color_index):
x, y, w, h = bbox
return TrafficSignal(x, y - 80, w, h, color_index, None)
class PassingDirects:
def __init__(self, left, right, straight):
self.left = left
self.right = right
self.straight = straight
def __str__(self):
return f'left: {self.left} straight: {self.straight} right: {self.right}'
@staticmethod
def allow():
return PassingDirects(True, True, True)
@staticmethod
def prohibit():
return PassingDirects(False, True, False)