Skip to content

Commit ee8607b

Browse files
(pose) migrate body parts to separate file (#224)
(pose) migrate body parts to separate file
1 parent 45fba9e commit ee8607b

File tree

3 files changed

+69
-40
lines changed

3 files changed

+69
-40
lines changed
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
from . import body_parts
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
# Yolo pose keypoint labels
2+
# 0: nose
3+
# 1: left-eye
4+
# 2: right-eye
5+
# 3: left-ear
6+
# 4: right-ear
7+
# 5: left-shoulder
8+
# 6: right-shoulder
9+
# 7: left-elbow
10+
# 8: right-elbow
11+
# 9: left-wrist
12+
# 10: right-wrist
13+
# 11: left-hip
14+
# 12: right-hip
15+
# 13: left-knee
16+
# 14: right-knee
17+
# 15: left-ankle
18+
# 16: right-ankle
19+
20+
BODY_PARTS = {
21+
"Nose": "Nose",
22+
"LEye": "LEye",
23+
"REye": "REye",
24+
"LEar": "LEar",
25+
"REar": "REar",
26+
"LShoulder": "LShoulder",
27+
"RShoulder": "RShoulder",
28+
"LElbow": "LElbow",
29+
"RElbow": "RElbow",
30+
"LWrist": "LWrist",
31+
"RWrist": "RWrist",
32+
"LHip": "LHip",
33+
"RHip": "RHip",
34+
"LKnee": "LKnee",
35+
"RKnee": "RKnee",
36+
"LAnkle": "LAnkle",
37+
"RAnkle": "RAnkle",
38+
}
39+
40+
BODY_PART_LINKS = [
41+
# The lowest index first
42+
# Matches the keys of BODY_PARTS
43+
# HEAD
44+
("Nose", "LEye"),
45+
("LEye", "LEar"),
46+
("Nose", "REye"),
47+
("LEye", "REye"),
48+
("REye", "REar"),
49+
# Left side
50+
("LEar", "LShoulder"),
51+
("LShoulder", "LElbow"),
52+
("LElbow", "LWrist"),
53+
("LShoulder", "LHip"),
54+
("LHip", "LKnee"),
55+
("LKnee", "LAnkle"),
56+
57+
# Right side
58+
("REar", "RShoulder"),
59+
("RShoulder", "RElbow"),
60+
("RElbow", "RWrist"),
61+
("RShoulder", "RHip"),
62+
("RHip", "RKnee"),
63+
("RKnee", "RAnkle"),
64+
]

image_recognition_pose_estimation/src/image_recognition_pose_estimation/yolo_pose_wrapper.py

Lines changed: 4 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -5,49 +5,11 @@
55
import numpy as np
66
import torch
77
from image_recognition_msgs.msg import CategoricalDistribution, CategoryProbability, Recognition
8+
from image_recognition_pose_estimation.body_parts import BODY_PARTS
89
from sensor_msgs.msg import RegionOfInterest
910
from ultralytics import YOLO
1011
from ultralytics.engine.results import Results
1112

12-
# Yolo pose keypoint labels
13-
# 0: nose
14-
# 1: left-eye
15-
# 2: right-eye
16-
# 3: left-ear
17-
# 4: right-ear
18-
# 5: left-shoulder
19-
# 6: right-shoulder
20-
# 7: left-elbow
21-
# 8: right-elbow
22-
# 9: left-wrist
23-
# 10: right-wrist
24-
# 11: left-hip
25-
# 12: right-hip
26-
# 13: left-knee
27-
# 14: right-knee
28-
# 15: left-ankle
29-
# 16: right-ankle
30-
31-
YOLO_POSE_KEYPOINT_LABELS = [
32-
"nose",
33-
"left-eye",
34-
"right-eye",
35-
"left-ear",
36-
"right-ear",
37-
"left-shoulder",
38-
"right-shoulder",
39-
"left-elbow",
40-
"right-elbow",
41-
"left-wrist",
42-
"right-wrist",
43-
"left-hip",
44-
"right-hip",
45-
"left-knee",
46-
"right-knee",
47-
"left-ankle",
48-
"right-ankle",
49-
]
50-
5113

5214
YOLO_POSE_PATTERN = re.compile(r"^yolov8(?:([nsml])|(x))-pose(?(2)-p6|)?.pt$")
5315

@@ -101,6 +63,8 @@ def detect_poses(self, image: np.ndarray, conf: float = 0.25) -> Tuple[List[Reco
10163
result = results[0] # Only using
10264
overlayed_image = result.plot(boxes=False)
10365

66+
body_parts = list(BODY_PARTS.values())
67+
10468
for i, person in enumerate(result.keypoints.cpu().numpy()):
10569
for j, (x, y, pred_conf) in enumerate(person.data[0]):
10670
if pred_conf > 0 and x > 0 and y > 0:
@@ -111,7 +75,7 @@ def detect_poses(self, image: np.ndarray, conf: float = 0.25) -> Tuple[List[Reco
11175
categorical_distribution=CategoricalDistribution(
11276
probabilities=[
11377
CategoryProbability(
114-
label=YOLO_POSE_KEYPOINT_LABELS[j],
78+
label=body_parts[j],
11579
probability=float(pred_conf),
11680
)
11781
]

0 commit comments

Comments
 (0)