Skip to content

Commit cd09857

Browse files
committed
add human keypoint app
1 parent 8ee4e09 commit cd09857

File tree

7 files changed

+62
-0
lines changed

7 files changed

+62
-0
lines changed

docs/doc/assets/body_keypoints.jpg

50 KB
Loading

docs/doc/en/vision/body_key_points.md

+2
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ With MaixPy, you can easily detect the coordinates of keypoints on human joints,
66

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

9+
![](../../assets/body_keypoints.jpg)
10+
911
## Usage
1012

1113
Using MaixPy's `maix.nn.YOLOv8` class, you can easily implement this functionality:

docs/doc/zh/vision/body_key_points.md

+2
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ title: MaixPy 检测人体关键点姿态检测
99

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

12+
![](../../assets/body_keypoints.jpg)
13+
1214
## 使用
1315

1416
使用 MaixPy 的 `maix.nn.YOLOv8` 类可以轻松实现:

projects/app_human_pose/.gitignore

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
2+
build
3+
dist
4+
/CMakeLists.txt
5+

projects/app_human_pose/app.yaml

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
id: human_pose
2+
name: Human Pose
3+
version: 1.0.0
4+
author: Sipeed Ltd
5+
icon: icon.json
6+
desc: Detect human body 17 keypoints.
7+
files:
8+
- icon.json
9+
- app.yaml
10+
- main.py

projects/app_human_pose/icon.json

+1
Large diffs are not rendered by default.

projects/app_human_pose/main.py

+42
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
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

Comments
 (0)