From 2d6e76a87ff3dd9493806f56f95747c977341112 Mon Sep 17 00:00:00 2001 From: Neucrack Date: Wed, 10 Jul 2024 17:00:18 +0800 Subject: [PATCH] add yolov8-seg app --- maix/version.py | 2 +- projects/app_yolov8_seg/.gitignore | 5 ++++ projects/app_yolov8_seg/app.yaml | 10 +++++++ projects/app_yolov8_seg/icon.png | Bin 0 -> 2938 bytes projects/app_yolov8_seg/main.py | 42 +++++++++++++++++++++++++++++ 5 files changed, 58 insertions(+), 1 deletion(-) create mode 100644 projects/app_yolov8_seg/.gitignore create mode 100644 projects/app_yolov8_seg/app.yaml create mode 100644 projects/app_yolov8_seg/icon.png create mode 100644 projects/app_yolov8_seg/main.py diff --git a/maix/version.py b/maix/version.py index a7980d36..54557b12 100644 --- a/maix/version.py +++ b/maix/version.py @@ -3,6 +3,6 @@ version_major = 4 version_minor = 3 -version_patch = 7 +version_patch = 8 __version__ = "{}.{}.{}".format(version_major, version_minor, version_patch) diff --git a/projects/app_yolov8_seg/.gitignore b/projects/app_yolov8_seg/.gitignore new file mode 100644 index 00000000..babf76a7 --- /dev/null +++ b/projects/app_yolov8_seg/.gitignore @@ -0,0 +1,5 @@ + +build +dist +/CMakeLists.txt + diff --git a/projects/app_yolov8_seg/app.yaml b/projects/app_yolov8_seg/app.yaml new file mode 100644 index 00000000..5cbf94ab --- /dev/null +++ b/projects/app_yolov8_seg/app.yaml @@ -0,0 +1,10 @@ +id: yolov8_seg +name: YOLOv8 Segmentation +version: 1.0.0 +author: Sipeed Ltd +icon: icon.png +desc: Detect human body 17 keypoints. +files: + - icon.png + - app.yaml + - main.py diff --git a/projects/app_yolov8_seg/icon.png b/projects/app_yolov8_seg/icon.png new file mode 100644 index 0000000000000000000000000000000000000000..f2be101e1a0b8ca26a7ca3c30c193ebc8eddb81e GIT binary patch literal 2938 zcmWlbc|6m99LGQ3&9TU>br_}`jghQ`v?eNZRbzxO%B+OtPD@`(2P&pwG$P~(MMPoK zAwwlsj+~Kll$hko&+m`-`}KG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=+SOF&)-nw6*1yfvFZIPR-yN-2gpMjIa4Vl`PvPvwh~evF zC&rZ@q4*DDl?5}BUjkxeZ);Q)>I~h=yf1*TIVqe2jX#7_ufN^NmYx2kbh-5f>m3=P zuke5)a2_rO{^MSj9XVc$+P%vI@s4}CXlFy8+PYH;4WuR0CcaycO= i@(MDcEHong`6@Kf<~x22(HpTArUCh&okj5hTJ(R>C`;Y| literal 0 HcmV?d00001 diff --git a/projects/app_yolov8_seg/main.py b/projects/app_yolov8_seg/main.py new file mode 100644 index 00000000..d3780d1a --- /dev/null +++ b/projects/app_yolov8_seg/main.py @@ -0,0 +1,42 @@ +from maix import camera, display, image, nn, app, time, touchscreen + +def is_in_button(x, y, btn_pos): + 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] + +def main(disp): + ts = touchscreen.TouchScreen() + detector = nn.YOLOv8(model="/root/models/yolov8n_seg.mud") + img_back = image.load("/maixapp/share/icon/ret.png") + back_rect = [0, 0, 32, 32] + + cam = camera.Camera(detector.input_width(), detector.input_height(), detector.input_format()) + 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]) + + while not app.need_exit(): + img = cam.read() + objs = detector.detect(img, conf_th = 0.5, iou_th = 0.45, keypoint_th = 0.5) + for obj in objs: + detector.draw_seg_mask(img, obj.x, obj.y, obj.seg_mask, threshold=127) + img.draw_rect(obj.x, obj.y, obj.w, obj.h, color = image.COLOR_RED) + msg = f'{detector.labels[obj.class_id]}: {obj.score:.2f}' + img.draw_string(obj.x, obj.y, msg, color = image.COLOR_RED) + # img.draw_rect(back_rect[0], back_rect[1], back_rect[2], back_rect[3], image.COLOR_BLACK, -1) + img.draw_image(0, 0, img_back) + disp.show(img) + x, y, preesed = ts.read() + if is_in_button(x, y, back_rect_disp): + app.set_exit_flag(True) + + + +disp = display.Display() +try: + main(disp) +except Exception: + import traceback + msg = traceback.format_exc() + img = image.Image(disp.width(), disp.height()) + img.draw_string(0, 0, msg, image.COLOR_WHITE) + disp.show(img) + while not app.need_exit(): + time.sleep_ms(100)