Skip to content

Commit

Permalink
add yolov8-seg app
Browse files Browse the repository at this point in the history
  • Loading branch information
Neutree committed Jul 10, 2024
1 parent 79917b1 commit 2d6e76a
Show file tree
Hide file tree
Showing 5 changed files with 58 additions and 1 deletion.
2 changes: 1 addition & 1 deletion maix/version.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@

version_major = 4
version_minor = 3
version_patch = 7
version_patch = 8

__version__ = "{}.{}.{}".format(version_major, version_minor, version_patch)
5 changes: 5 additions & 0 deletions projects/app_yolov8_seg/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@

build
dist
/CMakeLists.txt

10 changes: 10 additions & 0 deletions projects/app_yolov8_seg/app.yaml
Original file line number Diff line number Diff line change
@@ -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
Binary file added projects/app_yolov8_seg/icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
42 changes: 42 additions & 0 deletions projects/app_yolov8_seg/main.py
Original file line number Diff line number Diff line change
@@ -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)

0 comments on commit 2d6e76a

Please sign in to comment.