Skip to content

Commit a3b34d1

Browse files
committed
style: Code format.
Signed-off-by: lbuque <[email protected]>
1 parent b0b63fd commit a3b34d1

39 files changed

+3630
-3399
lines changed

examples/advanced/camera/cores3_example_camera_display.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,28 +9,30 @@
99

1010
img = None
1111

12+
1213
def setup():
1314
global img
1415
M5.begin()
1516
Widgets.fillScreen(0x222222)
1617
camera.init(pixformat=camera.RGB565, framesize=camera.QVGA)
1718

19+
1820
def loop():
1921
global img
2022
M5.update()
2123
img = camera.snapshot()
2224
M5.Lcd.show(img, 0, 0, 320, 240)
2325

24-
if __name__ == '__main__':
26+
27+
if __name__ == "__main__":
2528
try:
2629
setup()
2730
while True:
2831
loop()
2932
except (Exception, KeyboardInterrupt) as e:
3033
try:
3134
from utility import print_error_msg
35+
3236
print_error_msg(e)
3337
except ImportError:
3438
print("please update to latest firmware")
35-
36-

examples/advanced/code_scanner/qrcode_detect_example.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,15 @@
1212
img = None
1313
qrcode = None
1414

15+
1516
def setup():
1617
global img, qrcode
1718
M5.begin()
1819
Widgets.fillScreen(0x222222)
1920
camera.init(pixformat=camera.RGB565, framesize=camera.QVGA)
2021
camera.set_hmirror(False)
2122

23+
2224
def loop():
2325
global img, qrcode
2426
M5.update()
@@ -27,18 +29,19 @@ def loop():
2729
if qrcode:
2830
print(qrcode.payload())
2931
print(qrcode.type_name())
30-
img.draw_string(10, 10, str(qrcode.payload()), color=0x3333ff, scale=2)
32+
img.draw_string(10, 10, str(qrcode.payload()), color=0x3333FF, scale=2)
3133
M5.Lcd.show(img, 0, 0, 320, 240)
3234

33-
if __name__ == '__main__':
35+
36+
if __name__ == "__main__":
3437
try:
3538
setup()
3639
while True:
3740
loop()
3841
except (Exception, KeyboardInterrupt) as e:
3942
try:
4043
from utility import print_error_msg
44+
4145
print_error_msg(e)
4246
except ImportError:
4347
print("please update to latest firmware")
44-

examples/advanced/dl/cores3_example_human_face_detect.py

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,20 +9,21 @@
99
import image
1010

1111

12-
1312
img = None
1413
detector = None
1514
detection_result = None
1615
res = None
1716
kp = None
1817

18+
1919
def setup():
2020
global img, detector, detection_result, kp
2121
M5.begin()
2222
Widgets.fillScreen(0x222222)
2323
camera.init(pixformat=camera.RGB565, framesize=camera.QVGA)
2424
detector = dl.ObjectDetector(dl.model.HUMAN_FACE_DETECT)
2525

26+
2627
def loop():
2728
global img, detector, detection_result, kp
2829
M5.update()
@@ -31,23 +32,26 @@ def loop():
3132
if detection_result:
3233
for res in detection_result:
3334
kp = res.keypoint()
34-
img.draw_circle(kp[0], kp[1], 3, color=0x0000ff, thickness=1, fill=True)
35-
img.draw_circle(kp[2], kp[3], 3, color=0x00ff00, thickness=1, fill=True)
36-
img.draw_circle(kp[4], kp[5], 3, color=0xff0000, thickness=1, fill=True)
37-
img.draw_circle(kp[6], kp[7], 3, color=0x0000ff, thickness=1, fill=True)
38-
img.draw_circle(kp[8], kp[9], 3, color=0x00ff00, thickness=1, fill=True)
39-
img.draw_rectangle(res.x(), res.y(), res.w(), res.h(), color=0x3366ff, thickness=3, fill=False)
35+
img.draw_circle(kp[0], kp[1], 3, color=0x0000FF, thickness=1, fill=True)
36+
img.draw_circle(kp[2], kp[3], 3, color=0x00FF00, thickness=1, fill=True)
37+
img.draw_circle(kp[4], kp[5], 3, color=0xFF0000, thickness=1, fill=True)
38+
img.draw_circle(kp[6], kp[7], 3, color=0x0000FF, thickness=1, fill=True)
39+
img.draw_circle(kp[8], kp[9], 3, color=0x00FF00, thickness=1, fill=True)
40+
img.draw_rectangle(
41+
res.x(), res.y(), res.w(), res.h(), color=0x3366FF, thickness=3, fill=False
42+
)
4043
M5.Lcd.show(img, 0, 0, 320, 240)
4144

42-
if __name__ == '__main__':
45+
46+
if __name__ == "__main__":
4347
try:
4448
setup()
4549
while True:
4650
loop()
4751
except (Exception, KeyboardInterrupt) as e:
4852
try:
4953
from utility import print_error_msg
54+
5055
print_error_msg(e)
5156
except ImportError:
5257
print("please update to latest firmware")
53-

examples/advanced/dl/cores3_example_human_face_recognition.py

Lines changed: 128 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -29,27 +29,98 @@
2929
dl_recognize_result = None
3030

3131

32-
def dual_button_0_blue_wasClicked_event(state):
33-
global dual_button_0_blue, dual_button_0_red, sys_state, FACE_RECOGNIZE, FACE_ENROLL, FACE_DELETE, detector, img, dl_recognizer, detection_result, IDLE, kp, sys_state_prev, frame_count, res, dl_recognize_result
32+
def dual_button_0_blue_wasClicked_event(state): # noqa: N802
33+
global \
34+
dual_button_0_blue, \
35+
dual_button_0_red, \
36+
sys_state, \
37+
FACE_RECOGNIZE, \
38+
FACE_ENROLL, \
39+
FACE_DELETE, \
40+
detector, \
41+
img, \
42+
dl_recognizer, \
43+
detection_result, \
44+
IDLE, \
45+
kp, \
46+
sys_state_prev, \
47+
frame_count, \
48+
res, \
49+
dl_recognize_result
3450
sys_state = FACE_RECOGNIZE
3551

36-
def dual_button_0_red_wasClicked_event(state):
37-
global dual_button_0_blue, dual_button_0_red, sys_state, FACE_RECOGNIZE, FACE_ENROLL, FACE_DELETE, detector, img, dl_recognizer, detection_result, IDLE, kp, sys_state_prev, frame_count, res, dl_recognize_result
52+
53+
def dual_button_0_red_wasClicked_event(state): # noqa: N802
54+
global \
55+
dual_button_0_blue, \
56+
dual_button_0_red, \
57+
sys_state, \
58+
FACE_RECOGNIZE, \
59+
FACE_ENROLL, \
60+
FACE_DELETE, \
61+
detector, \
62+
img, \
63+
dl_recognizer, \
64+
detection_result, \
65+
IDLE, \
66+
kp, \
67+
sys_state_prev, \
68+
frame_count, \
69+
res, \
70+
dl_recognize_result
3871
sys_state = FACE_ENROLL
3972

40-
def btnPWR_wasClicked_event(state):
41-
global dual_button_0_blue, dual_button_0_red, sys_state, FACE_RECOGNIZE, FACE_ENROLL, FACE_DELETE, detector, img, dl_recognizer, detection_result, IDLE, kp, sys_state_prev, frame_count, res, dl_recognize_result
73+
74+
def btnPWR_wasClicked_event(state): # noqa: N802
75+
global \
76+
dual_button_0_blue, \
77+
dual_button_0_red, \
78+
sys_state, \
79+
FACE_RECOGNIZE, \
80+
FACE_ENROLL, \
81+
FACE_DELETE, \
82+
detector, \
83+
img, \
84+
dl_recognizer, \
85+
detection_result, \
86+
IDLE, \
87+
kp, \
88+
sys_state_prev, \
89+
frame_count, \
90+
res, \
91+
dl_recognize_result
4292
sys_state = FACE_DELETE
4393

94+
4495
def setup():
45-
global dual_button_0_blue, dual_button_0_red, sys_state, FACE_RECOGNIZE, FACE_ENROLL, FACE_DELETE, detector, img, dl_recognizer, detection_result, IDLE, kp, sys_state_prev, frame_count, res, dl_recognize_result
96+
global \
97+
dual_button_0_blue, \
98+
dual_button_0_red, \
99+
sys_state, \
100+
FACE_RECOGNIZE, \
101+
FACE_ENROLL, \
102+
FACE_DELETE, \
103+
detector, \
104+
img, \
105+
dl_recognizer, \
106+
detection_result, \
107+
IDLE, \
108+
kp, \
109+
sys_state_prev, \
110+
frame_count, \
111+
res, \
112+
dl_recognize_result
46113
M5.begin()
47114
Widgets.fillScreen(0x222222)
48115
BtnPWR.setCallback(type=BtnPWR.CB_TYPE.WAS_CLICKED, cb=btnPWR_wasClicked_event)
49116
camera.init(pixformat=camera.RGB565, framesize=camera.QVGA)
50117
dual_button_0_blue, dual_button_0_red = DualButtonUnit((8, 9))
51-
dual_button_0_blue.setCallback(type=dual_button_0_blue.CB_TYPE.WAS_CLICKED, cb=dual_button_0_blue_wasClicked_event)
52-
dual_button_0_red.setCallback(type=dual_button_0_red.CB_TYPE.WAS_CLICKED, cb=dual_button_0_red_wasClicked_event)
118+
dual_button_0_blue.setCallback(
119+
type=dual_button_0_blue.CB_TYPE.WAS_CLICKED, cb=dual_button_0_blue_wasClicked_event
120+
)
121+
dual_button_0_red.setCallback(
122+
type=dual_button_0_red.CB_TYPE.WAS_CLICKED, cb=dual_button_0_red_wasClicked_event
123+
)
53124
detector = dl.ObjectDetector(dl.model.HUMAN_FACE_DETECT)
54125
dl_recognizer = dl.HumanFaceRecognizer()
55126
IDLE = 0
@@ -60,8 +131,25 @@ def setup():
60131
sys_state_prev = IDLE
61132
frame_count = 0
62133

134+
63135
def loop():
64-
global dual_button_0_blue, dual_button_0_red, sys_state, FACE_RECOGNIZE, FACE_ENROLL, FACE_DELETE, detector, img, dl_recognizer, detection_result, IDLE, kp, sys_state_prev, frame_count, res, dl_recognize_result
136+
global \
137+
dual_button_0_blue, \
138+
dual_button_0_red, \
139+
sys_state, \
140+
FACE_RECOGNIZE, \
141+
FACE_ENROLL, \
142+
FACE_DELETE, \
143+
detector, \
144+
img, \
145+
dl_recognizer, \
146+
detection_result, \
147+
IDLE, \
148+
kp, \
149+
sys_state_prev, \
150+
frame_count, \
151+
res, \
152+
dl_recognize_result
65153
M5.update()
66154
dual_button_0_blue.tick(None)
67155
dual_button_0_red.tick(None)
@@ -70,13 +158,15 @@ def loop():
70158
if detection_result:
71159
for res in detection_result:
72160
kp = res.keypoint()
73-
img.draw_string(10, 10, str('face'), color=0x3333ff, scale=1)
74-
img.draw_circle(kp[0], kp[1], 3, color=0x3333ff, thickness=1, fill=True)
75-
img.draw_circle(kp[2], kp[3], 3, color=0x33ff33, thickness=1, fill=True)
76-
img.draw_circle(kp[4], kp[5], 3, color=0xff0000, thickness=1, fill=True)
77-
img.draw_circle(kp[6], kp[7], 3, color=0x3333ff, thickness=1, fill=True)
78-
img.draw_circle(kp[8], kp[9], 3, color=0x33ff33, thickness=1, fill=True)
79-
img.draw_rectangle(res.x(), res.y(), res.w(), res.h(), color=0x3366ff, thickness=3, fill=False)
161+
img.draw_string(10, 10, str("face"), color=0x3333FF, scale=1)
162+
img.draw_circle(kp[0], kp[1], 3, color=0x3333FF, thickness=1, fill=True)
163+
img.draw_circle(kp[2], kp[3], 3, color=0x33FF33, thickness=1, fill=True)
164+
img.draw_circle(kp[4], kp[5], 3, color=0xFF0000, thickness=1, fill=True)
165+
img.draw_circle(kp[6], kp[7], 3, color=0x3333FF, thickness=1, fill=True)
166+
img.draw_circle(kp[8], kp[9], 3, color=0x33FF33, thickness=1, fill=True)
167+
img.draw_rectangle(
168+
res.x(), res.y(), res.w(), res.h(), color=0x3366FF, thickness=3, fill=False
169+
)
80170
if sys_state == FACE_DELETE:
81171
dl_recognizer.delete_id()
82172
sys_state_prev = sys_state
@@ -91,34 +181,47 @@ def loop():
91181
elif sys_state == FACE_RECOGNIZE:
92182
dl_recognize_result = dl_recognizer.recognize(img, res.keypoint())
93183
if (dl_recognize_result.id()) > 0:
94-
print((str('similarity: ') + str((dl_recognize_result.similarity()))))
184+
print((str("similarity: ") + str((dl_recognize_result.similarity()))))
95185
sys_state_prev = sys_state
96186
sys_state = IDLE
97187
frame_count = 15
98188
else:
99-
img.draw_string(104, 10, str('face no detect'), color=0xff0000, scale=1)
189+
img.draw_string(104, 10, str("face no detect"), color=0xFF0000, scale=1)
100190
if frame_count > 0:
101191
frame_count = frame_count - 1
102192
if sys_state_prev == FACE_ENROLL:
103-
img.draw_string(116, 10, str('face enroll'), color=0x33ff33, scale=1)
193+
img.draw_string(116, 10, str("face enroll"), color=0x33FF33, scale=1)
104194
elif sys_state_prev == FACE_RECOGNIZE:
105195
if (dl_recognize_result.id()) > 0:
106-
img.draw_string(100, 10, str((str('recognize id: ') + str((dl_recognize_result.id())))), color=0x33ff33, scale=1)
196+
img.draw_string(
197+
100,
198+
10,
199+
str((str("recognize id: ") + str((dl_recognize_result.id())))),
200+
color=0x33FF33,
201+
scale=1,
202+
)
107203
else:
108-
img.draw_string(96, 10, str('no recognized'), color=0xff0000, scale=1)
204+
img.draw_string(96, 10, str("no recognized"), color=0xFF0000, scale=1)
109205
elif sys_state_prev == FACE_DELETE:
110-
img.draw_string(100, 10, str((str('remaining id: ') + str((dl_recognizer.enrolled_id_num())))), color=0xff0000, scale=1)
206+
img.draw_string(
207+
100,
208+
10,
209+
str((str("remaining id: ") + str((dl_recognizer.enrolled_id_num())))),
210+
color=0xFF0000,
211+
scale=1,
212+
)
111213
M5.Lcd.show(img, 0, 0, 320, 240)
112214

113-
if __name__ == '__main__':
215+
216+
if __name__ == "__main__":
114217
try:
115218
setup()
116219
while True:
117220
loop()
118221
except (Exception, KeyboardInterrupt) as e:
119222
try:
120223
from utility import print_error_msg
224+
121225
print_error_msg(e)
122226
except ImportError:
123227
print("please update to latest firmware")
124-

examples/advanced/dl/cores3_example_pedestrian_detect.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,15 @@
1515
res = None
1616
kp = None
1717

18+
1819
def setup():
1920
global img, detector, detection_result, kp
2021
M5.begin()
2122
Widgets.fillScreen(0x222222)
2223
camera.init(pixformat=camera.RGB565, framesize=camera.QVGA)
2324
detector = dl.ObjectDetector(dl.model.PEDESTRIAN_DETECT)
2425

26+
2527
def loop():
2628
global img, detector, detection_result, kp
2729
M5.update()
@@ -30,17 +32,21 @@ def loop():
3032
if detection_result:
3133
for res in detection_result:
3234
kp = res.keypoint()
33-
img.draw_rectangle(res.x(), res.y(), res.w(), res.h(), color=0x3366ff, thickness=3, fill=False)
35+
img.draw_rectangle(
36+
res.x(), res.y(), res.w(), res.h(), color=0x3366FF, thickness=3, fill=False
37+
)
3438
M5.Lcd.show(img, 0, 0, 320, 240)
3539

36-
if __name__ == '__main__':
40+
41+
if __name__ == "__main__":
3742
try:
3843
setup()
3944
while True:
4045
loop()
4146
except (Exception, KeyboardInterrupt) as e:
4247
try:
4348
from utility import print_error_msg
49+
4450
print_error_msg(e)
4551
except ImportError:
4652
print("please update to latest firmware")

0 commit comments

Comments
 (0)