Upload node_wrappers/openpose.py with huggingface_hub
Browse files- node_wrappers/openpose.py +48 -0
node_wrappers/openpose.py
ADDED
|
@@ -0,0 +1,48 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from ..utils import common_annotator_call, define_preprocessor_inputs, INPUT
|
| 2 |
+
import comfy.model_management as model_management
|
| 3 |
+
import json
|
| 4 |
+
|
| 5 |
+
class OpenPose_Preprocessor:
|
| 6 |
+
@classmethod
|
| 7 |
+
def INPUT_TYPES(s):
|
| 8 |
+
return define_preprocessor_inputs(
|
| 9 |
+
detect_hand=INPUT.COMBO(["enable", "disable"]),
|
| 10 |
+
detect_body=INPUT.COMBO(["enable", "disable"]),
|
| 11 |
+
detect_face=INPUT.COMBO(["enable", "disable"]),
|
| 12 |
+
resolution=INPUT.RESOLUTION(),
|
| 13 |
+
scale_stick_for_xinsr_cn=INPUT.COMBO(["disable", "enable"])
|
| 14 |
+
)
|
| 15 |
+
|
| 16 |
+
RETURN_TYPES = ("IMAGE", "POSE_KEYPOINT")
|
| 17 |
+
FUNCTION = "estimate_pose"
|
| 18 |
+
|
| 19 |
+
CATEGORY = "ControlNet Preprocessors/Faces and Poses Estimators"
|
| 20 |
+
|
| 21 |
+
def estimate_pose(self, image, detect_hand="enable", detect_body="enable", detect_face="enable", scale_stick_for_xinsr_cn="disable", resolution=512, **kwargs):
|
| 22 |
+
from custom_controlnet_aux.open_pose import OpenposeDetector
|
| 23 |
+
|
| 24 |
+
detect_hand = detect_hand == "enable"
|
| 25 |
+
detect_body = detect_body == "enable"
|
| 26 |
+
detect_face = detect_face == "enable"
|
| 27 |
+
scale_stick_for_xinsr_cn = scale_stick_for_xinsr_cn == "enable"
|
| 28 |
+
|
| 29 |
+
model = OpenposeDetector.from_pretrained().to(model_management.get_torch_device())
|
| 30 |
+
self.openpose_dicts = []
|
| 31 |
+
def func(image, **kwargs):
|
| 32 |
+
pose_img, openpose_dict = model(image, **kwargs)
|
| 33 |
+
self.openpose_dicts.append(openpose_dict)
|
| 34 |
+
return pose_img
|
| 35 |
+
|
| 36 |
+
out = common_annotator_call(func, image, include_hand=detect_hand, include_face=detect_face, include_body=detect_body, image_and_json=True, xinsr_stick_scaling=scale_stick_for_xinsr_cn, resolution=resolution)
|
| 37 |
+
del model
|
| 38 |
+
return {
|
| 39 |
+
'ui': { "openpose_json": [json.dumps(self.openpose_dicts, indent=4)] },
|
| 40 |
+
"result": (out, self.openpose_dicts)
|
| 41 |
+
}
|
| 42 |
+
|
| 43 |
+
NODE_CLASS_MAPPINGS = {
|
| 44 |
+
"OpenposePreprocessor": OpenPose_Preprocessor,
|
| 45 |
+
}
|
| 46 |
+
NODE_DISPLAY_NAME_MAPPINGS = {
|
| 47 |
+
"OpenposePreprocessor": "OpenPose Pose",
|
| 48 |
+
}
|