kijai / ComfyUI-LivePortraitKJ

ComfyUI nodes for LivePortrait

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

[feature request] Expose face direction

melMass opened this issue · comments

This here:

def sort_by_direction(faces, direction: str = 'large-small', face_center=None):
if len(faces) <= 0:
return faces
if direction == 'left-right':
return sorted(faces, key=lambda face: face['bbox'][0])
if direction == 'right-left':
return sorted(faces, key=lambda face: face['bbox'][0], reverse=True)
if direction == 'top-bottom':
return sorted(faces, key=lambda face: face['bbox'][1])
if direction == 'bottom-top':
return sorted(faces, key=lambda face: face['bbox'][1], reverse=True)
if direction == 'small-large':
return sorted(faces, key=lambda face: (face['bbox'][2] - face['bbox'][0]) * (face['bbox'][3] - face['bbox'][1]))
if direction == 'large-small':
return sorted(faces, key=lambda face: (face['bbox'][2] - face['bbox'][0]) * (face['bbox'][3] - face['bbox'][1]), reverse=True)
if direction == 'distance-from-retarget-face':
return sorted(faces, key=lambda face: (((face['bbox'][2]+face['bbox'][0])/2-face_center[0])**2+((face['bbox'][3]+face['bbox'][1])/2-face_center[1])**2)**0.5)
return faces

Defines how the index behaves. Currently, it defaults to large-small meaning 0 is the biggest face in the frame, and subsequent indexes are smaller faces... This should probably either default to left-right or be exposed

Should be exposed in my opinion, large-small as default makes sense in single face scenarios as you generally want to target the main face, while left-right probably makes most sense when doing multiple faces.