|
| 1 | +from maix import camera, display, image, nn, app, time, touchscreen |
| 2 | + |
| 3 | +def is_in_button(x, y, btn_pos): |
| 4 | + return x > btn_pos[0] and x < btn_pos[0] + btn_pos[2] and y > btn_pos[1] and y < btn_pos[1] + btn_pos[3] |
| 5 | + |
| 6 | +def main(disp): |
| 7 | + ts = touchscreen.TouchScreen() |
| 8 | + detector = nn.YOLOv8(model="/root/models/yolov8n_pose.mud") |
| 9 | + img_back = image.load("/maixapp/share/icon/ret.png") |
| 10 | + back_rect = [0, 0, 32, 32] |
| 11 | + |
| 12 | + cam = camera.Camera(detector.input_width(), detector.input_height(), detector.input_format()) |
| 13 | + back_rect_disp = image.resize_map_pos(cam.width(), cam.height(), disp.width(), disp.height(), image.Fit.FIT_CONTAIN, back_rect[0], back_rect[1], back_rect[2], back_rect[3]) |
| 14 | + |
| 15 | + while not app.need_exit(): |
| 16 | + img = cam.read() |
| 17 | + objs = detector.detect(img, conf_th = 0.5, iou_th = 0.45, keypoint_th = 0.5) |
| 18 | + for obj in objs: |
| 19 | + img.draw_rect(obj.x, obj.y, obj.w, obj.h, color = image.COLOR_RED) |
| 20 | + msg = f'{detector.labels[obj.class_id]}: {obj.score:.2f}' |
| 21 | + img.draw_string(obj.x, obj.y, msg, color = image.COLOR_RED) |
| 22 | + detector.draw_pose(img, obj.points, 8 if detector.input_width() > 480 else 4, image.COLOR_RED) |
| 23 | + # img.draw_rect(back_rect[0], back_rect[1], back_rect[2], back_rect[3], image.COLOR_BLACK, -1) |
| 24 | + img.draw_image(0, 0, img_back) |
| 25 | + disp.show(img) |
| 26 | + x, y, preesed = ts.read() |
| 27 | + if is_in_button(x, y, back_rect_disp): |
| 28 | + app.set_exit_flag(True) |
| 29 | + |
| 30 | + |
| 31 | + |
| 32 | +disp = display.Display() |
| 33 | +try: |
| 34 | + main(disp) |
| 35 | +except Exception: |
| 36 | + import traceback |
| 37 | + msg = traceback.format_exc() |
| 38 | + img = image.Image(disp.width(), disp.height()) |
| 39 | + img.draw_string(0, 0, msg, image.COLOR_WHITE) |
| 40 | + disp.show(img) |
| 41 | + while not app.need_exit(): |
| 42 | + time.sleep_ms(100) |
0 commit comments