-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathopenpose_keypoint_extractor.py
51 lines (45 loc) · 1.79 KB
/
openpose_keypoint_extractor.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
import json
from nodes import MAX_RESOLUTION
class OpenPoseKeyPointExtractor:
@classmethod
def INPUT_TYPES(s):
return {
"required": {
"pose_keypoint": ("POSE_KEYPOINT",),
"image_width": ("INT", { "min": 0, "max": MAX_RESOLUTION }),
"image_height": ("INT", { "min": 0, "max": MAX_RESOLUTION }),
"points_list": ("STRING", {"multiline": True, "default": ""}),
},
"optional": {
"person_number": ("INT", { "default": 0 }),
}
}
RETURN_TYPES = ("INT", "INT", "INT", "INT")
RETURN_NAMES = ("x", "y", "width", "height")
FUNCTION = "box_keypoints"
CATEGORY = "utils"
def get_keypoint_from_list(self, list, item):
idx_x = item*3
idx_y = idx_x + 1
idx_conf = idx_y + 1
return (list[idx_x], list[idx_y], list[idx_conf])
def box_keypoints(self, pose_keypoint, image_width, image_height, points_list, person_number=0):
points_we_want = [int(element) for element in points_list.split(",")]
min_x = MAX_RESOLUTION
min_y = MAX_RESOLUTION
max_x = 0
max_y = 0
for element in points_we_want:
(x,y,z) = self.get_keypoint_from_list(pose_keypoint[0]["people"][person_number]["pose_keypoints_2d"], element)
if x < min_x:
min_x = x
if y < min_y:
min_y = y
if x > max_x:
max_x = x
if y > max_y:
max_y = y
return (int(min_x*image_width), int(min_y*image_height), int((max_x-min_x)*image_width), int((max_y-min_y)*image_height))
NODE_CLASS_MAPPINGS = {
"Openpose Keypoint Extractor": OpenPoseKeyPointExtractor,
}