Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow dwpose to exclude hand and face outputs #110

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 13 additions & 7 deletions src/controlnet_aux/dwpose/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,20 @@
from . import util


def draw_pose(pose, H, W):
def draw_pose(pose, H, W, draw_body=True, draw_hand=True, draw_face=True):
bodies = pose['bodies']
faces = pose['faces']
hands = pose['hands']
candidate = bodies['candidate']
subset = bodies['subset']

canvas = np.zeros(shape=(H, W, 3), dtype=np.uint8)
canvas = util.draw_bodypose(canvas, candidate, subset)
canvas = util.draw_handpose(canvas, hands)
canvas = util.draw_facepose(canvas, faces)
if draw_body:
canvas = util.draw_bodypose(canvas, candidate, subset)
if draw_hand:
canvas = util.draw_handpose(canvas, hands)
if draw_face:
canvas = util.draw_facepose(canvas, faces)

return canvas

Expand All @@ -40,8 +43,11 @@ def to(self, device):
self.pose_estimation.to(device)
return self

def __call__(self, input_image, detect_resolution=512, image_resolution=512, output_type="pil", **kwargs):

def __call__(self, input_image, detect_resolution=512, image_resolution=512, include_body=True, include_hand=True, include_face=True, hand_and_face=None, output_type="pil", **kwargs):
if hand_and_face is not None:
include_hand = hand_and_face
include_face = hand_and_face

input_image = cv2.cvtColor(np.array(input_image, dtype=np.uint8), cv2.COLOR_RGB2BGR)

input_image = HWC3(input_image)
Expand Down Expand Up @@ -77,7 +83,7 @@ def __call__(self, input_image, detect_resolution=512, image_resolution=512, out
bodies = dict(candidate=body, subset=score)
pose = dict(bodies=bodies, hands=hands, faces=faces)

detected_map = draw_pose(pose, H, W)
detected_map = draw_pose(pose, H, W, draw_body=include_body, draw_hand=include_hand, draw_face=include_face)
detected_map = HWC3(detected_map)

img = resize_image(input_image, image_resolution)
Expand Down