Skip to content

Commit

Permalink
add human keypoint app
Browse files Browse the repository at this point in the history
  • Loading branch information
Neutree committed Jun 19, 2024
1 parent 8ee4e09 commit cd09857
Show file tree
Hide file tree
Showing 7 changed files with 62 additions and 0 deletions.
Binary file added docs/doc/assets/body_keypoints.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 2 additions & 0 deletions docs/doc/en/vision/body_key_points.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ With MaixPy, you can easily detect the coordinates of keypoints on human joints,

MaixPy implements human pose detection based on [YOLOv8-Pose](https://github.com/ultralytics/ultralytics), which can detect `17` keypoints on the human body.

![](../../assets/body_keypoints.jpg)

## Usage

Using MaixPy's `maix.nn.YOLOv8` class, you can easily implement this functionality:
Expand Down
2 changes: 2 additions & 0 deletions docs/doc/zh/vision/body_key_points.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ title: MaixPy 检测人体关键点姿态检测

MaixPy 实现了基于 [YOLOv8-Pose](https://github.com/ultralytics/ultralytics) 的人体姿态检测,可以检测到人体`17`个关键点。

![](../../assets/body_keypoints.jpg)

## 使用

使用 MaixPy 的 `maix.nn.YOLOv8` 类可以轻松实现:
Expand Down
5 changes: 5 additions & 0 deletions projects/app_human_pose/.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_human_pose/app.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
id: human_pose
name: Human Pose
version: 1.0.0
author: Sipeed Ltd
icon: icon.json
desc: Detect human body 17 keypoints.
files:
- icon.json
- app.yaml
- main.py
1 change: 1 addition & 0 deletions projects/app_human_pose/icon.json

Large diffs are not rendered by default.

42 changes: 42 additions & 0 deletions projects/app_human_pose/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_pose.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:
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)
detector.draw_pose(img, obj.points, 8 if detector.input_width() > 480 else 4, 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 cd09857

Please sign in to comment.