39
39
stop_background_color = (0 , 0 , 255 )
40
40
41
41
def create_ui_image ():
42
- # Initialize arrow button images. This could be done with a single image
43
- # that gets transposed and flipped, but ulab's transpose() doesn't support
44
- # the axes argument:
45
- # https://github.com/v923z/micropython-ulab/issues/731
46
- # So we instead create separate images for vertical and horizontal arrows
47
- img_arrow_vertical = np .zeros (button_shape , dtype = np .uint8 )
48
- img_arrow_vertical [:, :] = arrow_background_color
49
- img_arrow_horizontal = img_arrow_vertical .copy ()
50
- img_arrow_vertical = cv .arrowedLine (
51
- img_arrow_vertical ,
42
+ # Initialize arrow button image
43
+ img_arrow = np .zeros (button_shape , dtype = np .uint8 )
44
+ img_arrow [:, :] = arrow_background_color
45
+ img_arrow = cv .arrowedLine (
46
+ img_arrow ,
52
47
(button_cx , button_cy + arrow_length // 2 ),
53
48
(button_cx , button_cy - arrow_length // 2 ),
54
49
button_color ,
@@ -57,16 +52,6 @@ def create_ui_image():
57
52
0 ,
58
53
arrow_tip_length
59
54
)
60
- img_arrow_horizontal = cv .arrowedLine (
61
- img_arrow_horizontal ,
62
- (button_cx - arrow_length // 2 , button_cy ),
63
- (button_cx + arrow_length // 2 , button_cy ),
64
- button_color ,
65
- arrow_thickness ,
66
- cv .FILLED ,
67
- 0 ,
68
- arrow_tip_length
69
- )
70
55
71
56
# Initialize stop button image
72
57
img_button_stop = np .zeros (button_shape , dtype = np .uint8 )
@@ -92,25 +77,25 @@ def create_ui_image():
92
77
img_ui [
93
78
ui_cy - button_spacing - button_cy :ui_cy - button_spacing + button_cy ,
94
79
ui_cx - button_cx :ui_cx + button_cx
95
- ] = img_arrow_vertical
80
+ ] = img_arrow
96
81
97
82
# Draw the backward arrow below the stop button
98
83
img_ui [
99
84
ui_cy + button_spacing - button_cy :ui_cy + button_spacing + button_cy ,
100
85
ui_cx - button_cx :ui_cx + button_cx
101
- ] = img_arrow_vertical [::- 1 , :] # Flip the arrow image vertically
102
-
103
- # Draw the right arrow to the right of the stop button
86
+ ] = img_arrow [::- 1 , :] # Flip the arrow image vertically
87
+
88
+ # Draw the left arrow to the left of the stop button
104
89
img_ui [
105
90
ui_cy - button_cy :ui_cy + button_cy ,
106
- ui_cx + button_spacing - button_cx :ui_cx + button_spacing + button_cx
107
- ] = img_arrow_horizontal
91
+ ui_cx - button_spacing - button_cx :ui_cx - button_spacing + button_cx
92
+ ] = img_arrow . transpose (( 1 , 0 , 2 ))
108
93
109
- # Draw the left arrow to the left of the stop button
94
+ # Draw the right arrow to the right of the stop button
110
95
img_ui [
111
96
ui_cy - button_cy :ui_cy + button_cy ,
112
- ui_cx - button_spacing - button_cx :ui_cx - button_spacing + button_cx
113
- ] = img_arrow_horizontal [:, ::- 1 ] # Flip the arrow image horizontally
97
+ ui_cx + button_spacing - button_cx :ui_cx + button_spacing + button_cx
98
+ ] = img_arrow . transpose (( 1 , 0 , 2 )) [:, ::- 1 ] # Flip the arrow image horizontally
114
99
115
100
# Return the UI image
116
101
return img_ui
0 commit comments