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 00000000..f2be101e Binary files /dev/null and b/projects/app_yolov8_seg/icon.png differ 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)