Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
b3f055f698 | ||
|
|
7a154b1c48 | ||
|
|
133cf8ad26 | ||
|
|
e83f02ab3e | ||
|
|
bbb45a0d1a | ||
|
|
4c1c313095 | ||
|
|
bea92b2384 | ||
|
|
6bbfaaf21a | ||
|
|
4fed1e9f94 | ||
|
|
4a693b703f | ||
|
|
05c7d304da | ||
|
|
98750db9c9 |
@@ -5,5 +5,6 @@ venv
|
||||
.DS_Store
|
||||
checkpoints/
|
||||
checkpoint/
|
||||
.env
|
||||
|
||||
dwpose/keypoints/
|
||||
+558
-166
@@ -1089,8 +1089,7 @@ class TRI3DDWPose_Preprocessor:
|
||||
include_face=detect_face,
|
||||
include_body=detect_body)
|
||||
cur_file_dir = os.path.dirname(os.path.realpath(__file__))
|
||||
save_file_path = os.path.join(cur_file_dir,
|
||||
filename_path)
|
||||
save_file_path = os.path.join(cur_file_dir, filename_path)
|
||||
json.dump(pose_dict, open(save_file_path, 'w'))
|
||||
np_result = cv2.resize(np_result, (W, H),
|
||||
interpolation=cv2.INTER_AREA)
|
||||
@@ -1131,9 +1130,12 @@ class TRI3DPosetoImage:
|
||||
|
||||
canvas = np.zeros(shape=(height, width, 3), dtype=np.uint8)
|
||||
canvas = comfy_utils.draw_bodypose(canvas, keypoints)
|
||||
canvas = comfy_utils.draw_handpose(canvas, keypoints[88:109]) #right hand
|
||||
canvas = comfy_utils.draw_handpose(canvas,
|
||||
keypoints[88:109]) #right hand
|
||||
canvas = comfy_utils.draw_handpose(canvas, keypoints[109:]) #left hand
|
||||
canvas = torch.from_numpy(canvas.astype(np.float32)/255.0)[None,]
|
||||
canvas = torch.from_numpy(canvas.astype(np.float32) / 255.0)[
|
||||
None,
|
||||
]
|
||||
return (canvas, )
|
||||
|
||||
|
||||
@@ -1148,15 +1150,15 @@ class TRI3DPoseAdaption:
|
||||
"required": {
|
||||
"input_pose_json_file": ("STRING",{"default" : "dwpose/keypoints/input.json"}),
|
||||
"ref_pose_json_file": ("STRING",{"default" : "dwpose/keypoints/ref-pose.json"}),
|
||||
"image_angle": (["front", "back","back_fixed","back_fixed_left","back_fixed_right"], {"default": "front"}),
|
||||
"image_angle": (["front", "back","back_fixed_kid","back_fixed","back_fixed_left","back_fixed_right"], {"default": "front"}),
|
||||
"rotation_threshold": ("FLOAT", {
|
||||
"default": 5.0,
|
||||
"min": 0.0,
|
||||
"max": 15.0,
|
||||
"step": 0.01
|
||||
}),
|
||||
"garment_category":([" no_sleeve_garment", "half_sleeve_garment", "full_sleeve_garment", \
|
||||
"shorts", "trouser"], {"default": " no_sleeve_garment"})
|
||||
"garment_category":(["no_sleeve_garment", "half_sleeve_garment", "full_sleeve_garment", \
|
||||
"shorts", "trouser"], {"default": "no_sleeve_garment"})
|
||||
|
||||
|
||||
}
|
||||
@@ -1166,7 +1168,11 @@ class TRI3DPoseAdaption:
|
||||
FUNCTION = "main"
|
||||
CATEGORY = "TRI3D"
|
||||
|
||||
def main(self, input_pose_json_file, ref_pose_json_file, image_angle, rotation_threshold, garment_category):
|
||||
def main(self, input_pose_json_file, ref_pose_json_file, image_angle,
|
||||
rotation_threshold, garment_category):
|
||||
|
||||
print(image_angle, "image_angle")
|
||||
print(garment_category, "garment_category")
|
||||
from .dwpose import comfy_utils
|
||||
|
||||
if image_angle == "front":
|
||||
@@ -1175,7 +1181,8 @@ class TRI3DPoseAdaption:
|
||||
input_height = input_pose['height']
|
||||
input_width = input_pose['width']
|
||||
input_keypoints = input_pose['keypoints']
|
||||
canvas = np.zeros(shape=(input_height, input_width, 3), dtype=np.uint8)
|
||||
canvas = np.zeros(shape=(input_height, input_width, 3),
|
||||
dtype=np.uint8)
|
||||
|
||||
ref_pose = json.load(open(ref_pose_json_file))
|
||||
ref_height = ref_pose['height']
|
||||
@@ -1194,110 +1201,175 @@ class TRI3DPoseAdaption:
|
||||
rs_angle_diff = abs(rs_angle_2 - rs_angle_1)
|
||||
torso_angle_diff = abs(torso_angle_2 - torso_angle_1)
|
||||
|
||||
|
||||
similar_torso = False if (ls_angle_diff >= rotation_threshold) | (
|
||||
rs_angle_diff >= rotation_threshold) | (torso_angle_diff >= rotation_threshold) else True
|
||||
similar_torso = False if (
|
||||
ls_angle_diff >= rotation_threshold) | (
|
||||
rs_angle_diff >= rotation_threshold) | (
|
||||
torso_angle_diff >= rotation_threshold) else True
|
||||
|
||||
if similar_torso == False:
|
||||
canvas = torch.from_numpy(canvas.astype(np.float32) / 255.0)[
|
||||
None,
|
||||
]
|
||||
canvas = torch.from_numpy(
|
||||
canvas.astype(np.float32) / 255.0)[
|
||||
None,
|
||||
]
|
||||
return (canvas, similar_torso)
|
||||
|
||||
#Hands
|
||||
if input_keypoints[4] == [-1,-1]: input_keypoints[4] = ref_keypoints[4]
|
||||
if input_keypoints[7] == [-1,-1]: input_keypoints[7] = ref_keypoints[7]
|
||||
|
||||
input_keypoints[88:] = ref_keypoints[88:] #replace hands with reference hands
|
||||
|
||||
if garment_category not in ["half_sleeve_garment", "full_sleeve_garment"]:
|
||||
input_keypoints = comfy_utils.rotate(ref_keypoints, input_keypoints, 2, 3) # rotate left elbow
|
||||
input_keypoints = comfy_utils.scale(ref_keypoints, input_keypoints, 2, 5, 2, 3) #scaling w.r.t to shoulder to elbow ratio of ref pose
|
||||
#Hands
|
||||
if input_keypoints[4] == [-1, -1]:
|
||||
input_keypoints[4] = ref_keypoints[4]
|
||||
if input_keypoints[7] == [-1, -1]:
|
||||
input_keypoints[7] = ref_keypoints[7]
|
||||
|
||||
input_keypoints[88:] = ref_keypoints[
|
||||
88:] #replace hands with reference hands
|
||||
|
||||
if garment_category not in [
|
||||
"half_sleeve_garment", "full_sleeve_garment"
|
||||
]:
|
||||
input_keypoints = comfy_utils.rotate(ref_keypoints,
|
||||
input_keypoints, 2,
|
||||
3) # rotate left elbow
|
||||
input_keypoints = comfy_utils.scale(
|
||||
ref_keypoints, input_keypoints, 2, 5, 2,
|
||||
3) #scaling w.r.t to shoulder to elbow ratio of ref pose
|
||||
|
||||
prev_lw = input_keypoints[4]
|
||||
if garment_category != "full_sleeve_garment":
|
||||
input_keypoints = comfy_utils.rotate(ref_keypoints, input_keypoints, 3, 4) #rotate left wrist
|
||||
input_keypoints = comfy_utils.scale(ref_keypoints, input_keypoints, 2, 3, 3, 4) #scaling w.r.t to elbow to wrist ratio of ref pose
|
||||
input_keypoints = comfy_utils.rotate(ref_keypoints,
|
||||
input_keypoints, 3,
|
||||
4) #rotate left wrist
|
||||
input_keypoints = comfy_utils.scale(
|
||||
ref_keypoints, input_keypoints, 2, 3, 3,
|
||||
4) #scaling w.r.t to elbow to wrist ratio of ref pose
|
||||
|
||||
#moving to hand ponts to wrist
|
||||
input_keypoints[109:] = comfy_utils.move(input_keypoints[109], input_keypoints[4], input_keypoints[109:])
|
||||
input_keypoints[109:] = comfy_utils.move(ref_keypoints[4], ref_keypoints[109], input_keypoints[109:])
|
||||
#moving to hand ponts to wrist
|
||||
input_keypoints[109:] = comfy_utils.move(input_keypoints[109],
|
||||
input_keypoints[4],
|
||||
input_keypoints[109:])
|
||||
input_keypoints[109:] = comfy_utils.move(ref_keypoints[4],
|
||||
ref_keypoints[109],
|
||||
input_keypoints[109:])
|
||||
|
||||
# input_keypoints = comfy_utils.rotate_hand(ref_keypoints, input_keypoints, 109) #rotating left hand
|
||||
input_keypoints = comfy_utils.scale_hand(ref_keypoints, input_keypoints, 3, 4, 109) #scaling left hand w.r.t left wrist
|
||||
input_keypoints = comfy_utils.scale_hand(
|
||||
ref_keypoints, input_keypoints, 3, 4,
|
||||
109) #scaling left hand w.r.t left wrist
|
||||
|
||||
if garment_category not in ["half_sleeve_garment", "full_sleeve_garment"]:
|
||||
input_keypoints = comfy_utils.rotate(ref_keypoints, input_keypoints, 5, 6) #rotate right elbow
|
||||
input_keypoints = comfy_utils.scale(ref_keypoints, input_keypoints, 2, 5, 5, 6) #scaling w.r.t to shoulder to elbow ratio of ref pose
|
||||
if garment_category not in [
|
||||
"half_sleeve_garment", "full_sleeve_garment"
|
||||
]:
|
||||
input_keypoints = comfy_utils.rotate(ref_keypoints,
|
||||
input_keypoints, 5,
|
||||
6) #rotate right elbow
|
||||
input_keypoints = comfy_utils.scale(
|
||||
ref_keypoints, input_keypoints, 2, 5, 5,
|
||||
6) #scaling w.r.t to shoulder to elbow ratio of ref pose
|
||||
|
||||
prev_rw = input_keypoints[7]
|
||||
if garment_category != "full_sleeve_garment":
|
||||
input_keypoints = comfy_utils.rotate(ref_keypoints, input_keypoints, 6, 7) #rotate right wrist
|
||||
input_keypoints = comfy_utils.scale(ref_keypoints, input_keypoints, 5, 6, 6, 7) #scaling w.r.t to elbow to wrist ratio of ref pose
|
||||
input_keypoints = comfy_utils.rotate(ref_keypoints,
|
||||
input_keypoints, 6,
|
||||
7) #rotate right wrist
|
||||
input_keypoints = comfy_utils.scale(
|
||||
ref_keypoints, input_keypoints, 5, 6, 6,
|
||||
7) #scaling w.r.t to elbow to wrist ratio of ref pose
|
||||
|
||||
#moving hand points to wrist
|
||||
input_keypoints[88:109] = comfy_utils.move(input_keypoints[88], input_keypoints[7], input_keypoints[88:109])
|
||||
input_keypoints[88:109] = comfy_utils.move(ref_keypoints[7], ref_keypoints[88], input_keypoints[88:109])
|
||||
input_keypoints[88:109] = comfy_utils.move(input_keypoints[88],
|
||||
input_keypoints[7],
|
||||
input_keypoints[88:109])
|
||||
input_keypoints[88:109] = comfy_utils.move(ref_keypoints[7],
|
||||
ref_keypoints[88],
|
||||
input_keypoints[88:109])
|
||||
|
||||
# input_keypoints = comfy_utils.rotate_hand(ref_keypoints, input_keypoints, 88) #rotating right hand
|
||||
input_keypoints = comfy_utils.scale_hand(ref_keypoints, input_keypoints, 6, 7, 88) #scaling right hand w.r.t right wrist
|
||||
|
||||
input_keypoints = comfy_utils.scale_hand(
|
||||
ref_keypoints, input_keypoints, 6, 7,
|
||||
88) #scaling right hand w.r.t right wrist
|
||||
|
||||
#legs
|
||||
if garment_category not in ["trouser", "shorts"]:
|
||||
input_keypoints = comfy_utils.rotate(ref_keypoints, input_keypoints, 8, 9) #rotate left knee
|
||||
input_keypoints = comfy_utils.scale(ref_keypoints, input_keypoints, 1, 8, 8, 9) #scale left knee
|
||||
|
||||
input_keypoints = comfy_utils.rotate(ref_keypoints,
|
||||
input_keypoints, 8,
|
||||
9) #rotate left knee
|
||||
input_keypoints = comfy_utils.scale(ref_keypoints, input_keypoints,
|
||||
1, 8, 8, 9) #scale left knee
|
||||
|
||||
if garment_category != "trouser":
|
||||
input_keypoints = comfy_utils.rotate(ref_keypoints, input_keypoints, 9, 10) #rotate left foot
|
||||
input_keypoints = comfy_utils.scale(ref_keypoints, input_keypoints, 8, 9, 9, 10) #scaling w.r.t to knee to foot ratio of ref pose
|
||||
|
||||
input_keypoints = comfy_utils.rotate(ref_keypoints,
|
||||
input_keypoints, 9,
|
||||
10) #rotate left foot
|
||||
input_keypoints = comfy_utils.scale(
|
||||
ref_keypoints, input_keypoints, 8, 9, 9,
|
||||
10) #scaling w.r.t to knee to foot ratio of ref pose
|
||||
|
||||
if garment_category not in ["trouser", "shorts"]:
|
||||
input_keypoints = comfy_utils.rotate(ref_keypoints, input_keypoints, 11, 12) #rotate right knee
|
||||
input_keypoints = comfy_utils.scale(ref_keypoints, input_keypoints, 1, 11, 11, 12) #scale right knee
|
||||
|
||||
input_keypoints = comfy_utils.rotate(ref_keypoints,
|
||||
input_keypoints, 11,
|
||||
12) #rotate right knee
|
||||
input_keypoints = comfy_utils.scale(ref_keypoints, input_keypoints,
|
||||
1, 11, 11,
|
||||
12) #scale right knee
|
||||
|
||||
if garment_category != "trouser":
|
||||
input_keypoints = comfy_utils.rotate(ref_keypoints, input_keypoints, 12, 13) #rotate right foot
|
||||
input_keypoints = comfy_utils.scale(ref_keypoints, input_keypoints, 11, 12, 12, 13) #scaling w.r.t to knee to foot ratio of ref pose
|
||||
input_keypoints = comfy_utils.rotate(ref_keypoints,
|
||||
input_keypoints, 12,
|
||||
13) #rotate right foot
|
||||
input_keypoints = comfy_utils.scale(
|
||||
ref_keypoints, input_keypoints, 11, 12, 12,
|
||||
13) #scaling w.r.t to knee to foot ratio of ref pose
|
||||
|
||||
#face
|
||||
prev_nose = input_keypoints[0]
|
||||
input_keypoints = comfy_utils.rotate(ref_keypoints, input_keypoints, 1, 0) #rotate nose
|
||||
input_keypoints = comfy_utils.scale(ref_keypoints, input_keypoints, 2, 5, 1, 0) #scale neck to nose w.r.t to shoulder neck-nose len ratio of ref pose
|
||||
|
||||
input_keypoints = comfy_utils.rotate(ref_keypoints,
|
||||
input_keypoints, 1,
|
||||
0) #rotate nose
|
||||
input_keypoints = comfy_utils.scale(
|
||||
ref_keypoints, input_keypoints, 2, 5, 1, 0
|
||||
) #scale neck to nose w.r.t to shoulder neck-nose len ratio of ref pose
|
||||
|
||||
#changing face points to w.r.t to new nose point after rotation
|
||||
input_keypoints[14:18] = comfy_utils.move(prev_nose, input_keypoints[0], input_keypoints[14:18])
|
||||
input_keypoints[14:18] = comfy_utils.move(prev_nose,
|
||||
input_keypoints[0],
|
||||
input_keypoints[14:18])
|
||||
|
||||
input_keypoints = comfy_utils.rotate(ref_keypoints, input_keypoints, 0,
|
||||
14) #rotate left eye
|
||||
input_keypoints = comfy_utils.rotate(ref_keypoints,
|
||||
input_keypoints, 0,
|
||||
14) #rotate left eye
|
||||
input_keypoints = comfy_utils.scale(
|
||||
ref_keypoints, input_keypoints, 1, 0, 0,
|
||||
14) #scaling w.r.t to neck len to eye_nose len ratio of ref pose
|
||||
ref_keypoints, input_keypoints, 1, 0, 0, 14
|
||||
) #scaling w.r.t to neck len to eye_nose len ratio of ref pose
|
||||
|
||||
input_keypoints = comfy_utils.rotate(ref_keypoints, input_keypoints, 0,
|
||||
15) #rotate right eye
|
||||
input_keypoints = comfy_utils.rotate(ref_keypoints,
|
||||
input_keypoints, 0,
|
||||
15) #rotate right eye
|
||||
input_keypoints = comfy_utils.scale(
|
||||
ref_keypoints, input_keypoints, 1, 0, 0,
|
||||
15) #scaling w.r.t to neck len to eye_nose len ratio of ref pose
|
||||
ref_keypoints, input_keypoints, 1, 0, 0, 15
|
||||
) #scaling w.r.t to neck len to eye_nose len ratio of ref pose
|
||||
|
||||
input_keypoints = comfy_utils.rotate(ref_keypoints, input_keypoints,
|
||||
14, 16) #rotate left ear
|
||||
input_keypoints = comfy_utils.rotate(ref_keypoints,
|
||||
input_keypoints, 14,
|
||||
16) #rotate left ear
|
||||
input_keypoints = comfy_utils.scale(
|
||||
ref_keypoints, input_keypoints, 1, 0, 14,
|
||||
16) #scaling w.r.t to neck len to ear_nose len ratio of ref pose
|
||||
ref_keypoints, input_keypoints, 1, 0, 14, 16
|
||||
) #scaling w.r.t to neck len to ear_nose len ratio of ref pose
|
||||
|
||||
input_keypoints = comfy_utils.rotate(ref_keypoints, input_keypoints,
|
||||
15, 17) #rotate right ear
|
||||
input_keypoints = comfy_utils.rotate(ref_keypoints,
|
||||
input_keypoints, 15,
|
||||
17) #rotate right ear
|
||||
input_keypoints = comfy_utils.scale(
|
||||
ref_keypoints, input_keypoints, 1, 0, 15,
|
||||
17) #scaling w.r.t to neck len to ear_nose len ratio of ref pose
|
||||
ref_keypoints, input_keypoints, 1, 0, 15, 17
|
||||
) #scaling w.r.t to neck len to ear_nose len ratio of ref pose
|
||||
|
||||
canvas = comfy_utils.draw_bodypose(canvas, input_keypoints)
|
||||
canvas = comfy_utils.draw_handpose(canvas, input_keypoints[88:109]) #right hand
|
||||
canvas = comfy_utils.draw_handpose(canvas, input_keypoints[109:]) #left hand
|
||||
canvas = torch.from_numpy(canvas.astype(np.float32)/255.0)[None,]
|
||||
canvas = comfy_utils.draw_handpose(
|
||||
canvas, input_keypoints[88:109]) #right hand
|
||||
canvas = comfy_utils.draw_handpose(
|
||||
canvas, input_keypoints[109:]) #left hand
|
||||
canvas = torch.from_numpy(canvas.astype(np.float32) / 255.0)[
|
||||
None,
|
||||
]
|
||||
return (canvas, similar_torso)
|
||||
|
||||
|
||||
if 'back' in image_angle:
|
||||
|
||||
input_pose = json.load(open(input_pose_json_file))
|
||||
@@ -1306,47 +1378,59 @@ class TRI3DPoseAdaption:
|
||||
input_keypoints = input_pose['keypoints']
|
||||
|
||||
input_pose_type = comfy_utils.get_input_pose_type(input_keypoints)
|
||||
canvas = np.zeros(shape=(input_height, input_width, 3), dtype=np.uint8)
|
||||
canvas = np.zeros(shape=(input_height, input_width, 3),
|
||||
dtype=np.uint8)
|
||||
|
||||
if 'back_fixed' in image_angle:
|
||||
|
||||
back_pose_dir = pathlib.Path().resolve() / 'custom_nodes/tri3d-comfyui-nodes/samples/back_poses/'
|
||||
|
||||
back_pose_dir = pathlib.Path().resolve(
|
||||
) / 'custom_nodes/tri3d-comfyui-nodes/samples/back_poses/'
|
||||
back_pose_dictionary = {
|
||||
'back_fixed' : 'backpose.json',
|
||||
'back_fixed_left' : 'left_backpose.json',
|
||||
'back_fixed_right' : 'right_backpose.json'
|
||||
'back_fixed_kid': 'backpose_kid.json',
|
||||
'back_fixed': 'backpose.json',
|
||||
'back_fixed_left': 'left_backpose.json',
|
||||
'back_fixed_right': 'right_backpose.json'
|
||||
}
|
||||
|
||||
ref_pose_json_file = back_pose_dir / back_pose_dictionary[
|
||||
image_angle]
|
||||
|
||||
ref_pose_json_file = back_pose_dir / back_pose_dictionary[image_angle]
|
||||
|
||||
# /home/ubuntu/GITHUB/comfyanonymous/ComfyUI/custom_nodes/tri3d-comfyui-nodes
|
||||
print(ref_pose_json_file)
|
||||
ref_pose = json.load(open(ref_pose_json_file))
|
||||
|
||||
|
||||
ref_keypoints = ref_pose['keypoints']
|
||||
similar_torso = None
|
||||
|
||||
|
||||
#check torso similarity
|
||||
if garment_category not in ["shorts", "trouser"]:
|
||||
ls_angle_1, rs_angle_1, torso_angle_1 = comfy_utils.get_torso_angles(input_keypoints)
|
||||
ls_angle_2, rs_angle_2, torso_angle_2 = comfy_utils.get_torso_angles(ref_keypoints)
|
||||
ls_angle_1, rs_angle_1, torso_angle_1 = comfy_utils.get_torso_angles(
|
||||
input_keypoints)
|
||||
ls_angle_2, rs_angle_2, torso_angle_2 = comfy_utils.get_torso_angles(
|
||||
ref_keypoints)
|
||||
|
||||
ls_angle_diff = abs(ls_angle_2 - ls_angle_1)
|
||||
rs_angle_diff = abs(rs_angle_2 - rs_angle_1)
|
||||
torso_angle_diff = abs(torso_angle_2 - torso_angle_1)
|
||||
|
||||
similar_torso = False if (ls_angle_diff >= 5) | (rs_angle_diff >= 5) | (torso_angle_diff >= 5) else True
|
||||
similar_torso = False if (ls_angle_diff >= 5) | (
|
||||
rs_angle_diff >= 5) | (torso_angle_diff >= 5) else True
|
||||
|
||||
if similar_torso == False:
|
||||
canvas = torch.from_numpy(canvas.astype(np.float32)/255.0)[None,]
|
||||
canvas = torch.from_numpy(
|
||||
canvas.astype(np.float32) / 255.0)[
|
||||
None,
|
||||
]
|
||||
return (canvas, similar_torso)
|
||||
|
||||
#Removing the face points if existed
|
||||
null_indices = [i for i in range(len(ref_keypoints)) if ref_keypoints[i] == [-1,-1]]
|
||||
null_indices = [
|
||||
i for i in range(len(ref_keypoints))
|
||||
if ref_keypoints[i] == [-1, -1]
|
||||
]
|
||||
for i in null_indices:
|
||||
input_keypoints[i] = [-1,-1]
|
||||
|
||||
input_keypoints[i] = [-1, -1]
|
||||
|
||||
all_x = [i[0] for i in input_keypoints if i[0] != -1]
|
||||
min_width = min(all_x)
|
||||
max_width = max(all_x)
|
||||
@@ -1354,104 +1438,189 @@ class TRI3DPoseAdaption:
|
||||
if input_pose_type == "front_pose":
|
||||
#flip horizontally
|
||||
for i in range(len(input_keypoints)):
|
||||
x,y = input_keypoints[i]
|
||||
if input_keypoints[i] == [-1,-1]: continue
|
||||
input_keypoints[i] = [(max_width - x)+min_width, y]
|
||||
|
||||
x, y = input_keypoints[i]
|
||||
if input_keypoints[i] == [-1, -1]: continue
|
||||
input_keypoints[i] = [(max_width - x) + min_width, y]
|
||||
|
||||
#Hands
|
||||
if input_keypoints[4] == [-1,-1]: input_keypoints[4] = ref_keypoints[4]
|
||||
if input_keypoints[7] == [-1,-1]: input_keypoints[7] = ref_keypoints[7]
|
||||
input_keypoints[88:] = ref_keypoints[88:] #replace hands with reference hands
|
||||
|
||||
if garment_category not in ["half_sleeve_garment", "full_sleeve_garment"]:
|
||||
input_keypoints = comfy_utils.rotate(ref_keypoints, input_keypoints, 2, 3) # rotate left elbow
|
||||
input_keypoints = comfy_utils.scale(ref_keypoints, input_keypoints, 2, 5, 2, 3) #scaling w.r.t to shoulder to elbow ratio of ref pose
|
||||
if input_keypoints[4] == [-1, -1]:
|
||||
input_keypoints[4] = ref_keypoints[4]
|
||||
if input_keypoints[7] == [-1, -1]:
|
||||
input_keypoints[7] = ref_keypoints[7]
|
||||
input_keypoints[88:] = ref_keypoints[
|
||||
88:] #replace hands with reference hands
|
||||
|
||||
if garment_category not in [
|
||||
"half_sleeve_garment", "full_sleeve_garment"
|
||||
]:
|
||||
input_keypoints = comfy_utils.rotate(ref_keypoints,
|
||||
input_keypoints, 2,
|
||||
3) # rotate left elbow
|
||||
input_keypoints = comfy_utils.scale(
|
||||
ref_keypoints, input_keypoints, 2, 5, 2,
|
||||
3) #scaling w.r.t to shoulder to elbow ratio of ref pose
|
||||
|
||||
prev_lw = input_keypoints[4]
|
||||
if garment_category != "full_sleeve_garment":
|
||||
input_keypoints = comfy_utils.rotate(ref_keypoints, input_keypoints, 3, 4) #rotate left wrist
|
||||
input_keypoints = comfy_utils.scale(ref_keypoints, input_keypoints, 2, 3, 3, 4) #scaling w.r.t to elbow to wrist ratio of ref pose
|
||||
input_keypoints = comfy_utils.rotate(ref_keypoints,
|
||||
input_keypoints, 3,
|
||||
4) #rotate left wrist
|
||||
input_keypoints = comfy_utils.scale(
|
||||
ref_keypoints, input_keypoints, 2, 3, 3,
|
||||
4) #scaling w.r.t to elbow to wrist ratio of ref pose
|
||||
|
||||
#moving to hand ponts to wrist
|
||||
input_keypoints[109:] = comfy_utils.move(input_keypoints[109], input_keypoints[4], input_keypoints[109:])
|
||||
input_keypoints[109:] = comfy_utils.move(ref_keypoints[4], ref_keypoints[109], input_keypoints[109:])
|
||||
#moving to hand ponts to wrist
|
||||
input_keypoints[109:] = comfy_utils.move(input_keypoints[109],
|
||||
input_keypoints[4],
|
||||
input_keypoints[109:])
|
||||
input_keypoints[109:] = comfy_utils.move(ref_keypoints[4],
|
||||
ref_keypoints[109],
|
||||
input_keypoints[109:])
|
||||
|
||||
# input_keypoints = comfy_utils.rotate_hand(ref_keypoints, input_keypoints, 109) #rotating left hand
|
||||
input_keypoints = comfy_utils.scale_hand(ref_keypoints, input_keypoints, 3, 4, 109) #scaling left hand w.r.t left wrist
|
||||
input_keypoints = comfy_utils.scale_hand(
|
||||
ref_keypoints, input_keypoints, 3, 4,
|
||||
109) #scaling left hand w.r.t left wrist
|
||||
|
||||
if garment_category not in ["half_sleeve_garment", "full_sleeve_garment"]:
|
||||
input_keypoints = comfy_utils.rotate(ref_keypoints, input_keypoints, 5, 6) #rotate right elbow
|
||||
input_keypoints = comfy_utils.scale(ref_keypoints, input_keypoints, 2, 5, 5, 6) #scaling w.r.t to shoulder to elbow ratio of ref pose
|
||||
if garment_category not in [
|
||||
"half_sleeve_garment", "full_sleeve_garment"
|
||||
]:
|
||||
input_keypoints = comfy_utils.rotate(ref_keypoints,
|
||||
input_keypoints, 5,
|
||||
6) #rotate right elbow
|
||||
input_keypoints = comfy_utils.scale(
|
||||
ref_keypoints, input_keypoints, 2, 5, 5,
|
||||
6) #scaling w.r.t to shoulder to elbow ratio of ref pose
|
||||
|
||||
prev_rw = input_keypoints[7]
|
||||
if garment_category != "full_sleeve_garment":
|
||||
input_keypoints = comfy_utils.rotate(ref_keypoints, input_keypoints, 6, 7) #rotate right wrist
|
||||
input_keypoints = comfy_utils.scale(ref_keypoints, input_keypoints, 5, 6, 6, 7) #scaling w.r.t to elbow to wrist ratio of ref pose
|
||||
input_keypoints = comfy_utils.rotate(ref_keypoints,
|
||||
input_keypoints, 6,
|
||||
7) #rotate right wrist
|
||||
input_keypoints = comfy_utils.scale(
|
||||
ref_keypoints, input_keypoints, 5, 6, 6,
|
||||
7) #scaling w.r.t to elbow to wrist ratio of ref pose
|
||||
|
||||
#moving hand points to wrist
|
||||
input_keypoints[88:109] = comfy_utils.move(input_keypoints[88], input_keypoints[7], input_keypoints[88:109])
|
||||
input_keypoints[88:109] = comfy_utils.move(ref_keypoints[7], ref_keypoints[88], input_keypoints[88:109])
|
||||
input_keypoints[88:109] = comfy_utils.move(input_keypoints[88],
|
||||
input_keypoints[7],
|
||||
input_keypoints[88:109])
|
||||
input_keypoints[88:109] = comfy_utils.move(ref_keypoints[7],
|
||||
ref_keypoints[88],
|
||||
input_keypoints[88:109])
|
||||
|
||||
# input_keypoints = comfy_utils.rotate_hand(ref_keypoints, input_keypoints, 88) #rotating right hand
|
||||
input_keypoints = comfy_utils.scale_hand(ref_keypoints, input_keypoints, 6, 7, 88) #scaling right hand w.r.t right wrist
|
||||
input_keypoints = comfy_utils.scale_hand(
|
||||
ref_keypoints, input_keypoints, 6, 7,
|
||||
88) #scaling right hand w.r.t right wrist
|
||||
|
||||
#legs
|
||||
if garment_category not in ["trouser", "shorts"]:
|
||||
input_keypoints = comfy_utils.rotate(ref_keypoints, input_keypoints, 8, 9) #rotate left knee
|
||||
input_keypoints = comfy_utils.scale(ref_keypoints, input_keypoints, 1, 8, 8, 9) #scale left knee
|
||||
input_keypoints = comfy_utils.rotate(ref_keypoints,
|
||||
input_keypoints, 8,
|
||||
9) #rotate left knee
|
||||
input_keypoints = comfy_utils.scale(ref_keypoints, input_keypoints,
|
||||
1, 8, 8, 9) #scale left knee
|
||||
|
||||
if garment_category != "trouser":
|
||||
input_keypoints = comfy_utils.rotate(ref_keypoints, input_keypoints, 9, 10) #rotate left foot
|
||||
input_keypoints = comfy_utils.scale(ref_keypoints, input_keypoints, 8, 9, 9, 10) #scaling w.r.t to knee to foot ratio of ref pose
|
||||
input_keypoints = comfy_utils.rotate(ref_keypoints,
|
||||
input_keypoints, 9,
|
||||
10) #rotate left foot
|
||||
input_keypoints = comfy_utils.scale(
|
||||
ref_keypoints, input_keypoints, 8, 9, 9,
|
||||
10) #scaling w.r.t to knee to foot ratio of ref pose
|
||||
|
||||
if garment_category not in ["half_sleeve_garment", "full_sleeve_garment"]:
|
||||
input_keypoints = comfy_utils.rotate(ref_keypoints, input_keypoints, 11, 12) #rotate right knee
|
||||
input_keypoints = comfy_utils.scale(ref_keypoints, input_keypoints, 1, 11, 11, 12) #scale right knee
|
||||
if garment_category not in [
|
||||
"half_sleeve_garment", "full_sleeve_garment"
|
||||
]:
|
||||
input_keypoints = comfy_utils.rotate(ref_keypoints,
|
||||
input_keypoints, 11,
|
||||
12) #rotate right knee
|
||||
input_keypoints = comfy_utils.scale(ref_keypoints, input_keypoints,
|
||||
1, 11, 11,
|
||||
12) #scale right knee
|
||||
|
||||
if garment_category != "trouser":
|
||||
input_keypoints = comfy_utils.rotate(ref_keypoints, input_keypoints, 12, 13) #rotate right foot
|
||||
input_keypoints = comfy_utils.scale(ref_keypoints, input_keypoints, 11, 12, 12, 13) #scaling w.r.t to knee to foot ratio of ref pose
|
||||
input_keypoints = comfy_utils.rotate(ref_keypoints,
|
||||
input_keypoints, 12,
|
||||
13) #rotate right foot
|
||||
input_keypoints = comfy_utils.scale(
|
||||
ref_keypoints, input_keypoints, 11, 12, 12,
|
||||
13) #scaling w.r.t to knee to foot ratio of ref pose
|
||||
|
||||
#face
|
||||
input_keypoints[14:18] = ref_keypoints[14:18]
|
||||
input_keypoints[0] = ref_keypoints[0]
|
||||
|
||||
if input_keypoints[0] == [-1, -1] and input_keypoints[14] == [
|
||||
-1, -1
|
||||
] and input_keypoints[15] == [-1, -1]:
|
||||
input_keypoints = comfy_utils.rotate(ref_keypoints,
|
||||
input_keypoints, 1,
|
||||
16) #rotate left ear
|
||||
input_keypoints = comfy_utils.scale(
|
||||
ref_keypoints, input_keypoints, 2, 5, 1, 16
|
||||
) #scaling w.r.t to neck len to ear_nose len ratio of ref pose
|
||||
|
||||
|
||||
if input_keypoints[0] == [-1,-1] and input_keypoints[14] == [-1,-1] and input_keypoints[15] == [-1,-1]:
|
||||
input_keypoints = comfy_utils.rotate(ref_keypoints, input_keypoints, 1, 16) #rotate left ear
|
||||
input_keypoints = comfy_utils.scale(ref_keypoints, input_keypoints, 2, 5, 1, 16) #scaling w.r.t to neck len to ear_nose len ratio of ref pose
|
||||
|
||||
input_keypoints = comfy_utils.rotate(ref_keypoints, input_keypoints, 1,17) #rotate right ear
|
||||
input_keypoints = comfy_utils.scale(ref_keypoints, input_keypoints, 2, 5, 1, 17) #scaling w.r.t to neck len to ear_nose len ratio of ref pose
|
||||
input_keypoints = comfy_utils.rotate(ref_keypoints,
|
||||
input_keypoints, 1,
|
||||
17) #rotate right ear
|
||||
input_keypoints = comfy_utils.scale(
|
||||
ref_keypoints, input_keypoints, 2, 5, 1, 17
|
||||
) #scaling w.r.t to neck len to ear_nose len ratio of ref pose
|
||||
else:
|
||||
prev_nose = input_keypoints[0]
|
||||
input_keypoints = comfy_utils.rotate(ref_keypoints, input_keypoints, 1, 0) #rotate nose
|
||||
input_keypoints = comfy_utils.scale(ref_keypoints, input_keypoints, 2, 5, 1, 0) #scale neck to nose w.r.t to shoulder neck-nose len ratio of ref pose
|
||||
|
||||
input_keypoints = comfy_utils.rotate(ref_keypoints,
|
||||
input_keypoints, 1,
|
||||
0) #rotate nose
|
||||
input_keypoints = comfy_utils.scale(
|
||||
ref_keypoints, input_keypoints, 2, 5, 1, 0
|
||||
) #scale neck to nose w.r.t to shoulder neck-nose len ratio of ref pose
|
||||
|
||||
#changing face points to w.r.t to new nose point after rotation
|
||||
input_keypoints[14:18] = comfy_utils.move(prev_nose, input_keypoints[0], input_keypoints[14:18])
|
||||
input_keypoints[14:18] = comfy_utils.move(
|
||||
prev_nose, input_keypoints[0], input_keypoints[14:18])
|
||||
|
||||
if input_keypoints[14] != [-1,-1]:
|
||||
input_keypoints = comfy_utils.rotate(ref_keypoints, input_keypoints, 0, 14) #rotate left eye
|
||||
input_keypoints = comfy_utils.scale(ref_keypoints, input_keypoints, 1, 0, 0, 14) #scaling w.r.t to neck len to eye_nose len ratio of ref pose
|
||||
if input_keypoints[14] != [-1, -1]:
|
||||
input_keypoints = comfy_utils.rotate(
|
||||
ref_keypoints, input_keypoints, 0,
|
||||
14) #rotate left eye
|
||||
input_keypoints = comfy_utils.scale(
|
||||
ref_keypoints, input_keypoints, 1, 0, 0, 14
|
||||
) #scaling w.r.t to neck len to eye_nose len ratio of ref pose
|
||||
|
||||
if input_keypoints[15] != [-1,-1]:
|
||||
input_keypoints = comfy_utils.rotate(ref_keypoints, input_keypoints, 0, 15) #rotate right eye
|
||||
input_keypoints = comfy_utils.scale(ref_keypoints, input_keypoints, 1, 0, 0, 15) #scaling w.r.t to neck len to eye_nose len ratio of ref pose
|
||||
if input_keypoints[15] != [-1, -1]:
|
||||
input_keypoints = comfy_utils.rotate(
|
||||
ref_keypoints, input_keypoints, 0,
|
||||
15) #rotate right eye
|
||||
input_keypoints = comfy_utils.scale(
|
||||
ref_keypoints, input_keypoints, 1, 0, 0, 15
|
||||
) #scaling w.r.t to neck len to eye_nose len ratio of ref pose
|
||||
|
||||
if input_keypoints[16] != [-1,-1]:
|
||||
input_keypoints = comfy_utils.rotate(ref_keypoints, input_keypoints, 14, 16) #rotate left ear
|
||||
input_keypoints = comfy_utils.scale(ref_keypoints, input_keypoints, 1, 0, 14, 16) #scaling w.r.t to neck len to ear_nose len ratio of ref pose
|
||||
if input_keypoints[16] != [-1, -1]:
|
||||
input_keypoints = comfy_utils.rotate(
|
||||
ref_keypoints, input_keypoints, 14,
|
||||
16) #rotate left ear
|
||||
input_keypoints = comfy_utils.scale(
|
||||
ref_keypoints, input_keypoints, 1, 0, 14, 16
|
||||
) #scaling w.r.t to neck len to ear_nose len ratio of ref pose
|
||||
|
||||
if input_keypoints[17] != [-1,-1]:
|
||||
input_keypoints = comfy_utils.rotate(ref_keypoints, input_keypoints, 15,17) #rotate right ear
|
||||
input_keypoints = comfy_utils.scale(ref_keypoints, input_keypoints, 1, 0, 15, 17) #scaling w.r.t to neck len to ear_nose len ratio of ref pose
|
||||
if input_keypoints[17] != [-1, -1]:
|
||||
input_keypoints = comfy_utils.rotate(
|
||||
ref_keypoints, input_keypoints, 15,
|
||||
17) #rotate right ear
|
||||
input_keypoints = comfy_utils.scale(
|
||||
ref_keypoints, input_keypoints, 1, 0, 15, 17
|
||||
) #scaling w.r.t to neck len to ear_nose len ratio of ref pose
|
||||
|
||||
canvas = comfy_utils.draw_bodypose(canvas, input_keypoints)
|
||||
canvas = comfy_utils.draw_handpose(canvas, input_keypoints[88:109]) #right hand
|
||||
canvas = comfy_utils.draw_handpose(canvas, input_keypoints[109:]) #left hand
|
||||
canvas = torch.from_numpy(canvas.astype(np.float32)/255.0)[None,]
|
||||
canvas = comfy_utils.draw_handpose(
|
||||
canvas, input_keypoints[88:109]) #right hand
|
||||
canvas = comfy_utils.draw_handpose(
|
||||
canvas, input_keypoints[109:]) #left hand
|
||||
canvas = torch.from_numpy(canvas.astype(np.float32) / 255.0)[
|
||||
None,
|
||||
]
|
||||
return (canvas, similar_torso)
|
||||
|
||||
|
||||
@@ -1491,9 +1660,13 @@ class TRI3DLoadPoseJson:
|
||||
|
||||
canvas = np.zeros(shape=(height, width, 3), dtype=np.uint8)
|
||||
canvas = comfy_utils.draw_bodypose(canvas, keypoints)
|
||||
canvas = comfy_utils.draw_handpose(canvas, keypoints[88:109]) #right hand
|
||||
canvas = comfy_utils.draw_handpose(canvas, keypoints[109:]) #left hand
|
||||
canvas = torch.from_numpy(canvas.astype(np.float32)/255.0)[None,]
|
||||
canvas = comfy_utils.draw_handpose(canvas,
|
||||
keypoints[88:109]) #right hand
|
||||
canvas = comfy_utils.draw_handpose(canvas,
|
||||
keypoints[109:]) #left hand
|
||||
canvas = torch.from_numpy(canvas.astype(np.float32) / 255.0)[
|
||||
None,
|
||||
]
|
||||
else:
|
||||
canvas = np.zeros(shape=(height, width, 3), dtype=np.uint8)
|
||||
# if 'A' in i.getbands():
|
||||
@@ -1611,6 +1784,125 @@ class FloatToImage:
|
||||
|
||||
return image
|
||||
|
||||
|
||||
class TRI3D_recolor_LAB_manual:
|
||||
|
||||
@classmethod
|
||||
def INPUT_TYPES(s):
|
||||
return {
|
||||
"required": {
|
||||
"image_input": ("IMAGE", ),
|
||||
"mask_input": ("IMAGE", ),
|
||||
"factor_mean": ("FLOAT", {
|
||||
"default": 1.0,
|
||||
"min": 0.0,
|
||||
"max": 10.0,
|
||||
"step": 0.01
|
||||
}),
|
||||
"factor_sigma": ("FLOAT", {
|
||||
"default": 1.0,
|
||||
"min": 0.0,
|
||||
"max": 10.0,
|
||||
"step": 0.01
|
||||
}),
|
||||
}
|
||||
}
|
||||
|
||||
RETURN_TYPES = ("IMAGE", )
|
||||
FUNCTION = "recolor"
|
||||
CATEGORY = "TRI3D"
|
||||
|
||||
def recolor(self, image_input, mask_input, factor_mean, factor_sigma):
|
||||
|
||||
def get_mu_sigma(array_input, mask_input):
|
||||
|
||||
import numpy as np
|
||||
import math
|
||||
|
||||
array_input = array_input.astype(dtype=np.float32).flatten()
|
||||
mask_input = mask_input.flatten()
|
||||
|
||||
sum = np.sum(mask_input)
|
||||
mean = np.sum(array_input * mask_input) / sum
|
||||
|
||||
array_input -= mean
|
||||
array_input *= mask_input
|
||||
sigma = math.sqrt(np.sum(np.square(array_input)) / sum)
|
||||
|
||||
return mean, sigma
|
||||
|
||||
def do_recolor(image, mask, mean, sigma):
|
||||
|
||||
import cv2
|
||||
import numpy as np
|
||||
import math
|
||||
|
||||
image_original = image.copy()
|
||||
|
||||
mask = (mask > 127).astype(dtype=np.uint8)
|
||||
|
||||
sum = np.sum(mask.flatten())
|
||||
|
||||
for i in range(3):
|
||||
image[:, :, i] *= mask
|
||||
|
||||
image = cv2.cvtColor(image, cv2.COLOR_BGR2LAB)
|
||||
|
||||
image = image.astype(dtype=np.float32)
|
||||
|
||||
for i in range(1):
|
||||
|
||||
mu_1, sigma_1 = get_mu_sigma(array_input=image[:, :, i],
|
||||
mask_input=mask)
|
||||
|
||||
image[:, :, i] = (((image[:, :, i] - mu_1) / sigma_1) *
|
||||
(sigma * sigma_1)) + (mean * mu_1)
|
||||
|
||||
image = np.clip(image, 0, 255)
|
||||
image = image.astype(dtype=np.uint8)
|
||||
image = cv2.cvtColor(image, cv2.COLOR_LAB2BGR)
|
||||
|
||||
for i in range(3):
|
||||
|
||||
image_original[:, :,
|
||||
i] = (image_original[:, :, i] *
|
||||
(1 - mask)) + (image[:, :, i] * mask)
|
||||
|
||||
return image_original
|
||||
|
||||
def from_torch_image(image):
|
||||
|
||||
image = image.squeeze().cpu().numpy() * 255.0
|
||||
image = np.clip(image, 0, 255).astype(np.uint8)
|
||||
|
||||
return image
|
||||
|
||||
def to_torch_image(image):
|
||||
|
||||
import numpy as np
|
||||
import torch
|
||||
image = image.astype(dtype=np.float32)
|
||||
image /= 255.0
|
||||
image = torch.from_numpy(image)[
|
||||
None,
|
||||
]
|
||||
image = image.unsqueeze(0)
|
||||
return image
|
||||
|
||||
image = from_torch_image(image=image_input)
|
||||
|
||||
mask = from_torch_image(image=mask_input)[:, :, 0]
|
||||
|
||||
image_output = do_recolor(image=image,
|
||||
mask=mask,
|
||||
mean=factor_mean,
|
||||
sigma=factor_sigma)
|
||||
|
||||
image_output = to_torch_image(image=image_output)
|
||||
|
||||
return image_output
|
||||
|
||||
|
||||
class TRI3D_recolor_LAB:
|
||||
|
||||
@classmethod
|
||||
@@ -1981,8 +2273,6 @@ class TRI3D_recolor:
|
||||
return image_output
|
||||
|
||||
|
||||
|
||||
|
||||
class TRI3D_image_mask_2_box:
|
||||
|
||||
def __init__(self):
|
||||
@@ -2036,6 +2326,7 @@ class TRI3D_image_mask_box_2_image:
|
||||
image = to_torch_image(image)
|
||||
return image
|
||||
|
||||
|
||||
class TRI3D_clipdrop_bgremove_api:
|
||||
|
||||
def __init__(self):
|
||||
@@ -2062,13 +2353,14 @@ class TRI3D_clipdrop_bgremove_api:
|
||||
CLIPDROP_API_KEY = os.getenv('CLIPDROP_API_KEY')
|
||||
|
||||
# CLIPDROP_API_KEY = os.environ.get('CLIPDROP_API_KEY')
|
||||
|
||||
|
||||
r = requests.post('https://clipdrop-api.co/remove-background/v1',
|
||||
files = {
|
||||
'image_file': ("mannequin.jpg", enc_image.tobytes(), 'image/jpeg'),
|
||||
},
|
||||
headers = { 'x-api-key': CLIPDROP_API_KEY}
|
||||
)
|
||||
files={
|
||||
'image_file':
|
||||
("mannequin.jpg", enc_image.tobytes(),
|
||||
'image/jpeg'),
|
||||
},
|
||||
headers={'x-api-key': CLIPDROP_API_KEY})
|
||||
if (r.ok):
|
||||
pass
|
||||
else:
|
||||
@@ -2078,7 +2370,9 @@ class TRI3D_clipdrop_bgremove_api:
|
||||
# print("decoded output",output.shape)
|
||||
# mask = output[:,:,3]
|
||||
# output = output[:,:,0:3]
|
||||
output = torch.from_numpy(output.astype(np.float32)/255.0)[None,]
|
||||
output = torch.from_numpy(output.astype(np.float32) / 255.0)[
|
||||
None,
|
||||
]
|
||||
# print("converted image to torch")
|
||||
# print(output.shape)
|
||||
# mask = torch.from_numpy(mask.astype(np.float32)/255.0)[None,]
|
||||
@@ -2086,6 +2380,100 @@ class TRI3D_clipdrop_bgremove_api:
|
||||
# print(mask.shape)
|
||||
return output,
|
||||
|
||||
|
||||
class TRI3DAdjustNeck:
|
||||
|
||||
def __init__(self):
|
||||
pass
|
||||
|
||||
@classmethod
|
||||
def INPUT_TYPES(s):
|
||||
return {
|
||||
"required": {
|
||||
"posemap_json_file_path": ("STRING", {
|
||||
"default":
|
||||
"dwpose/keypoints/input.json"
|
||||
}),
|
||||
# "age_group" :(["10-12 yrs"],{"default":"10-12 yrs"}),
|
||||
"neck_shoulder_ratio": ("FLOAT", {
|
||||
"default": 0.7,
|
||||
"min": 0.0,
|
||||
"max": 1.0,
|
||||
"step": 0.01
|
||||
}),
|
||||
"save_json_file_path": ("STRING", {
|
||||
"default":
|
||||
"dwpose/keypoints/output.json"
|
||||
})
|
||||
},
|
||||
}
|
||||
|
||||
FUNCTION = "run"
|
||||
RETURN_TYPES = ("IMAGE", "STRING")
|
||||
CATEGORY = "TRI3D"
|
||||
|
||||
def run(self, posemap_json_file_path, neck_shoulder_ratio,
|
||||
save_json_file_path):
|
||||
from .dwpose import comfy_utils
|
||||
|
||||
# age_to_ratio = {"10-12 yrs": 0.65}
|
||||
|
||||
input_pose = json.load(open(posemap_json_file_path))
|
||||
input_height = input_pose['height']
|
||||
input_width = input_pose['width']
|
||||
input_keypoints = input_pose['keypoints']
|
||||
|
||||
ref_x1, ref_y1 = input_keypoints[2] #left shoulder
|
||||
ref_x2, ref_y2 = input_keypoints[5] #right_shoulder
|
||||
|
||||
x1, y1 = input_keypoints[1] #neck
|
||||
x2, y2 = input_keypoints[0] #nose
|
||||
prev_nose = input_keypoints[0]
|
||||
|
||||
ref_len = np.linalg.norm(
|
||||
np.array([ref_x1, ref_y1]) - np.array(
|
||||
[ref_x2, ref_y2])) #ref body part length i.e. shoulder length
|
||||
targ_len = np.linalg.norm(np.array([x1, y1]) - np.array([
|
||||
x2, y2
|
||||
])) #targ body part length i.e. neck length - neck to nose length
|
||||
|
||||
input_targ_ref_len = targ_len / ref_len #neck to shoulder ratio
|
||||
print("neck to shoulder ratio found", input_targ_ref_len)
|
||||
print("neck to shoulder ratio target", neck_shoulder_ratio)
|
||||
#scale the coords
|
||||
# scale = age_to_ratio[age_group] / input_targ_ref_len
|
||||
scale = neck_shoulder_ratio / input_targ_ref_len
|
||||
|
||||
x2_scaled = x1 + (x2 - x1) * scale
|
||||
y2_scaled = y1 + (y2 - y1) * scale
|
||||
input_keypoints[0] = [x2_scaled, y2_scaled]
|
||||
|
||||
#changing face points to w.r.t to new nose point after rotation
|
||||
input_keypoints[14:18] = comfy_utils.move(prev_nose,
|
||||
input_keypoints[0],
|
||||
input_keypoints[14:18])
|
||||
|
||||
canvas = np.zeros(shape=(input_height, input_width, 3), dtype=np.uint8)
|
||||
canvas = comfy_utils.draw_bodypose(canvas, input_keypoints)
|
||||
canvas = comfy_utils.draw_handpose(
|
||||
canvas, input_keypoints[88:109]) #right hand
|
||||
canvas = comfy_utils.draw_handpose(canvas,
|
||||
input_keypoints[109:]) #left hand
|
||||
canvas = torch.from_numpy(canvas.astype(np.float32) / 255.0)[
|
||||
None,
|
||||
]
|
||||
|
||||
output_pose = {
|
||||
"height": input_height,
|
||||
"width": input_width,
|
||||
"keypoints": input_keypoints
|
||||
}
|
||||
cur_file_dir = os.path.dirname(os.path.realpath(__file__))
|
||||
save_json_file_path = os.path.join(cur_file_dir, save_json_file_path)
|
||||
json.dump(output_pose, open(save_json_file_path, 'w'))
|
||||
return (canvas, save_json_file_path)
|
||||
|
||||
|
||||
# A dictionary that contains all nodes you want to export with their names
|
||||
# NOTE: names should be globally unique
|
||||
NODE_CLASS_MAPPINGS = {
|
||||
@@ -2107,10 +2495,12 @@ NODE_CLASS_MAPPINGS = {
|
||||
"tri3d-recolor-mask-RGB_space": TRI3D_recolor_RGB,
|
||||
"tri3d-image-mask-2-box": TRI3D_image_mask_2_box,
|
||||
"tri3d-image-mask-box-2-image": TRI3D_image_mask_box_2_image,
|
||||
"tri3d-clipdrop-bgremove-api": TRI3D_clipdrop_bgremove_api
|
||||
"tri3d-clipdrop-bgremove-api": TRI3D_clipdrop_bgremove_api,
|
||||
"tri3d-adjust-neck": TRI3DAdjustNeck,
|
||||
"tri3d_recolor_lab_manual": TRI3D_recolor_LAB_manual,
|
||||
}
|
||||
|
||||
VERSION = "2.3"
|
||||
VERSION = "2.4.2"
|
||||
# A dictionary that contains the friendly/humanly readable titles for the nodes
|
||||
NODE_DISPLAY_NAME_MAPPINGS = {
|
||||
"tri3d-atr-parse-batch": "ATR Parse Batch" + " v" + VERSION,
|
||||
@@ -2133,5 +2523,7 @@ NODE_DISPLAY_NAME_MAPPINGS = {
|
||||
"tri3d-recolor-mask-RGB_space": "Recolor mask RGB space" + " v" + VERSION,
|
||||
"tri3d--image-mask-2-box": "Extract box from image" + " v" + VERSION,
|
||||
"tri3d-image-mask-box-2-image": "Stitch box to image" + " v" + VERSION,
|
||||
"tri3d-clipdrop-bgremove-api": "RemBG ClipDrop" + " v" + VERSION
|
||||
"tri3d-clipdrop-bgremove-api": "RemBG ClipDrop" + " v" + VERSION,
|
||||
"tri3d-adjust-neck": "Adjust Neck" + " v" + VERSION,
|
||||
"tri3d_recolor_lab_manual": "Adjust color manually" + " v" + VERSION,
|
||||
}
|
||||
|
||||
@@ -0,0 +1,526 @@
|
||||
{
|
||||
"height": 512,
|
||||
"width": 512,
|
||||
"keypoints": [
|
||||
[
|
||||
-1,
|
||||
-1
|
||||
],
|
||||
[
|
||||
252,
|
||||
130
|
||||
],
|
||||
[
|
||||
302,
|
||||
130
|
||||
],
|
||||
[
|
||||
316,
|
||||
213
|
||||
],
|
||||
[
|
||||
323,
|
||||
284
|
||||
],
|
||||
[
|
||||
202,
|
||||
130
|
||||
],
|
||||
[
|
||||
191,
|
||||
211
|
||||
],
|
||||
[
|
||||
187,
|
||||
282
|
||||
],
|
||||
[
|
||||
282,
|
||||
278
|
||||
],
|
||||
[
|
||||
280,
|
||||
380
|
||||
],
|
||||
[
|
||||
280,
|
||||
484
|
||||
],
|
||||
[
|
||||
222,
|
||||
278
|
||||
],
|
||||
[
|
||||
226,
|
||||
382
|
||||
],
|
||||
[
|
||||
222,
|
||||
480
|
||||
],
|
||||
[
|
||||
-1,
|
||||
-1
|
||||
],
|
||||
[
|
||||
-1,
|
||||
-1
|
||||
],
|
||||
[
|
||||
286,
|
||||
72
|
||||
],
|
||||
[
|
||||
227,
|
||||
73
|
||||
],
|
||||
[
|
||||
257,
|
||||
59
|
||||
],
|
||||
[
|
||||
257,
|
||||
63
|
||||
],
|
||||
[
|
||||
257,
|
||||
65
|
||||
],
|
||||
[
|
||||
253,
|
||||
67
|
||||
],
|
||||
[
|
||||
-2,
|
||||
-2
|
||||
],
|
||||
[
|
||||
-2,
|
||||
-2
|
||||
],
|
||||
[
|
||||
-2,
|
||||
-2
|
||||
],
|
||||
[
|
||||
-2,
|
||||
-2
|
||||
],
|
||||
[
|
||||
-2,
|
||||
-2
|
||||
],
|
||||
[
|
||||
279,
|
||||
79
|
||||
],
|
||||
[
|
||||
-2,
|
||||
-2
|
||||
],
|
||||
[
|
||||
243,
|
||||
67
|
||||
],
|
||||
[
|
||||
253,
|
||||
71
|
||||
],
|
||||
[
|
||||
257,
|
||||
69
|
||||
],
|
||||
[
|
||||
-2,
|
||||
-2
|
||||
],
|
||||
[
|
||||
-2,
|
||||
-2
|
||||
],
|
||||
[
|
||||
-2,
|
||||
-2
|
||||
],
|
||||
[
|
||||
275,
|
||||
61
|
||||
],
|
||||
[
|
||||
279,
|
||||
59
|
||||
],
|
||||
[
|
||||
255,
|
||||
55
|
||||
],
|
||||
[
|
||||
-2,
|
||||
-2
|
||||
],
|
||||
[
|
||||
-2,
|
||||
-2
|
||||
],
|
||||
[
|
||||
255,
|
||||
59
|
||||
],
|
||||
[
|
||||
255,
|
||||
59
|
||||
],
|
||||
[
|
||||
255,
|
||||
59
|
||||
],
|
||||
[
|
||||
255,
|
||||
57
|
||||
],
|
||||
[
|
||||
255,
|
||||
57
|
||||
],
|
||||
[
|
||||
255,
|
||||
59
|
||||
],
|
||||
[
|
||||
255,
|
||||
59
|
||||
],
|
||||
[
|
||||
255,
|
||||
61
|
||||
],
|
||||
[
|
||||
255,
|
||||
63
|
||||
],
|
||||
[
|
||||
277,
|
||||
67
|
||||
],
|
||||
[
|
||||
275,
|
||||
67
|
||||
],
|
||||
[
|
||||
277,
|
||||
67
|
||||
],
|
||||
[
|
||||
277,
|
||||
67
|
||||
],
|
||||
[
|
||||
277,
|
||||
67
|
||||
],
|
||||
[
|
||||
255,
|
||||
59
|
||||
],
|
||||
[
|
||||
255,
|
||||
57
|
||||
],
|
||||
[
|
||||
257,
|
||||
59
|
||||
],
|
||||
[
|
||||
257,
|
||||
61
|
||||
],
|
||||
[
|
||||
257,
|
||||
59
|
||||
],
|
||||
[
|
||||
255,
|
||||
59
|
||||
],
|
||||
[
|
||||
255,
|
||||
59
|
||||
],
|
||||
[
|
||||
257,
|
||||
59
|
||||
],
|
||||
[
|
||||
257,
|
||||
59
|
||||
],
|
||||
[
|
||||
-2,
|
||||
-2
|
||||
],
|
||||
[
|
||||
255,
|
||||
59
|
||||
],
|
||||
[
|
||||
-2,
|
||||
-2
|
||||
],
|
||||
[
|
||||
-2,
|
||||
-2
|
||||
],
|
||||
[
|
||||
-2,
|
||||
-2
|
||||
],
|
||||
[
|
||||
-2,
|
||||
-2
|
||||
],
|
||||
[
|
||||
279,
|
||||
71
|
||||
],
|
||||
[
|
||||
243,
|
||||
67
|
||||
],
|
||||
[
|
||||
279,
|
||||
73
|
||||
],
|
||||
[
|
||||
277,
|
||||
71
|
||||
],
|
||||
[
|
||||
279,
|
||||
71
|
||||
],
|
||||
[
|
||||
-2,
|
||||
-2
|
||||
],
|
||||
[
|
||||
-2,
|
||||
-2
|
||||
],
|
||||
[
|
||||
-2,
|
||||
-2
|
||||
],
|
||||
[
|
||||
-2,
|
||||
-2
|
||||
],
|
||||
[
|
||||
-2,
|
||||
-2
|
||||
],
|
||||
[
|
||||
-2,
|
||||
-2
|
||||
],
|
||||
[
|
||||
279,
|
||||
69
|
||||
],
|
||||
[
|
||||
279,
|
||||
71
|
||||
],
|
||||
[
|
||||
277,
|
||||
71
|
||||
],
|
||||
[
|
||||
279,
|
||||
71
|
||||
],
|
||||
[
|
||||
277,
|
||||
69
|
||||
],
|
||||
[
|
||||
-2,
|
||||
-2
|
||||
],
|
||||
[
|
||||
250,
|
||||
56
|
||||
],
|
||||
[
|
||||
263,
|
||||
63
|
||||
],
|
||||
[
|
||||
186.65255255416977,
|
||||
285
|
||||
],
|
||||
[
|
||||
196.65255255416977,
|
||||
291
|
||||
],
|
||||
[
|
||||
199.65255255416977,
|
||||
298
|
||||
],
|
||||
[
|
||||
201.65255255416977,
|
||||
306
|
||||
],
|
||||
[
|
||||
201.65255255416977,
|
||||
310
|
||||
],
|
||||
[
|
||||
194.65255255416977,
|
||||
308
|
||||
],
|
||||
[
|
||||
196.65255255416977,
|
||||
312
|
||||
],
|
||||
[
|
||||
199.65255255416977,
|
||||
316
|
||||
],
|
||||
[
|
||||
203.65255255416977,
|
||||
318
|
||||
],
|
||||
[
|
||||
190.65255255416977,
|
||||
308
|
||||
],
|
||||
[
|
||||
192.65255255416977,
|
||||
314
|
||||
],
|
||||
[
|
||||
194.65255255416977,
|
||||
318
|
||||
],
|
||||
[
|
||||
201.65255255416977,
|
||||
320
|
||||
],
|
||||
[
|
||||
186.65255255416977,
|
||||
308
|
||||
],
|
||||
[
|
||||
186.65255255416977,
|
||||
314
|
||||
],
|
||||
[
|
||||
190.65255255416977,
|
||||
318
|
||||
],
|
||||
[
|
||||
196.65255255416977,
|
||||
320
|
||||
],
|
||||
[
|
||||
182.65255255416977,
|
||||
308
|
||||
],
|
||||
[
|
||||
184.65255255416977,
|
||||
312
|
||||
],
|
||||
[
|
||||
186.65255255416977,
|
||||
316
|
||||
],
|
||||
[
|
||||
190.65255255416977,
|
||||
318
|
||||
],
|
||||
[
|
||||
323,
|
||||
287
|
||||
],
|
||||
[
|
||||
313,
|
||||
298
|
||||
],
|
||||
[
|
||||
310,
|
||||
305
|
||||
],
|
||||
[
|
||||
310,
|
||||
312
|
||||
],
|
||||
[
|
||||
310,
|
||||
317
|
||||
],
|
||||
[
|
||||
320,
|
||||
315
|
||||
],
|
||||
[
|
||||
317,
|
||||
319
|
||||
],
|
||||
[
|
||||
313,
|
||||
324
|
||||
],
|
||||
[
|
||||
308,
|
||||
326
|
||||
],
|
||||
[
|
||||
322,
|
||||
315
|
||||
],
|
||||
[
|
||||
320,
|
||||
322
|
||||
],
|
||||
[
|
||||
315,
|
||||
326
|
||||
],
|
||||
[
|
||||
308,
|
||||
326
|
||||
],
|
||||
[
|
||||
324,
|
||||
317
|
||||
],
|
||||
[
|
||||
320,
|
||||
322
|
||||
],
|
||||
[
|
||||
315,
|
||||
326
|
||||
],
|
||||
[
|
||||
310,
|
||||
326
|
||||
],
|
||||
[
|
||||
327,
|
||||
317
|
||||
],
|
||||
[
|
||||
324,
|
||||
322
|
||||
],
|
||||
[
|
||||
320,
|
||||
324
|
||||
],
|
||||
[
|
||||
315,
|
||||
326
|
||||
]
|
||||
]
|
||||
}
|
||||
@@ -0,0 +1,526 @@
|
||||
{
|
||||
"height": 512,
|
||||
"width": 512,
|
||||
"keypoints": [
|
||||
[
|
||||
-1,
|
||||
-1
|
||||
],
|
||||
[
|
||||
254,
|
||||
118
|
||||
],
|
||||
[
|
||||
292,
|
||||
118
|
||||
],
|
||||
[
|
||||
306,
|
||||
194
|
||||
],
|
||||
[
|
||||
310,
|
||||
262
|
||||
],
|
||||
[
|
||||
216,
|
||||
118
|
||||
],
|
||||
[
|
||||
200,
|
||||
193
|
||||
],
|
||||
[
|
||||
195,
|
||||
260
|
||||
],
|
||||
[
|
||||
278,
|
||||
251
|
||||
],
|
||||
[
|
||||
286,
|
||||
357
|
||||
],
|
||||
[
|
||||
285.99326159010275,
|
||||
462.45102588957826
|
||||
],
|
||||
[
|
||||
228,
|
||||
254
|
||||
],
|
||||
[
|
||||
230,
|
||||
353
|
||||
],
|
||||
[
|
||||
231.99326159010275,
|
||||
458.45102588957826
|
||||
],
|
||||
[
|
||||
-1,
|
||||
-1
|
||||
],
|
||||
[
|
||||
-1,
|
||||
-1
|
||||
],
|
||||
[
|
||||
277,
|
||||
62
|
||||
],
|
||||
[
|
||||
241,
|
||||
62
|
||||
],
|
||||
[
|
||||
234,
|
||||
53
|
||||
],
|
||||
[
|
||||
234,
|
||||
60
|
||||
],
|
||||
[
|
||||
234,
|
||||
64
|
||||
],
|
||||
[
|
||||
236,
|
||||
71
|
||||
],
|
||||
[
|
||||
236,
|
||||
75
|
||||
],
|
||||
[
|
||||
241,
|
||||
77
|
||||
],
|
||||
[
|
||||
243,
|
||||
82
|
||||
],
|
||||
[
|
||||
247,
|
||||
84
|
||||
],
|
||||
[
|
||||
254,
|
||||
84
|
||||
],
|
||||
[
|
||||
258,
|
||||
84
|
||||
],
|
||||
[
|
||||
263,
|
||||
84
|
||||
],
|
||||
[
|
||||
267,
|
||||
82
|
||||
],
|
||||
[
|
||||
272,
|
||||
80
|
||||
],
|
||||
[
|
||||
274,
|
||||
75
|
||||
],
|
||||
[
|
||||
276,
|
||||
71
|
||||
],
|
||||
[
|
||||
278,
|
||||
66
|
||||
],
|
||||
[
|
||||
281,
|
||||
62
|
||||
],
|
||||
[
|
||||
243,
|
||||
44
|
||||
],
|
||||
[
|
||||
245,
|
||||
42
|
||||
],
|
||||
[
|
||||
247,
|
||||
42
|
||||
],
|
||||
[
|
||||
252,
|
||||
42
|
||||
],
|
||||
[
|
||||
256,
|
||||
42
|
||||
],
|
||||
[
|
||||
265,
|
||||
44
|
||||
],
|
||||
[
|
||||
269,
|
||||
44
|
||||
],
|
||||
[
|
||||
272,
|
||||
46
|
||||
],
|
||||
[
|
||||
276,
|
||||
49
|
||||
],
|
||||
[
|
||||
278,
|
||||
51
|
||||
],
|
||||
[
|
||||
261,
|
||||
51
|
||||
],
|
||||
[
|
||||
258,
|
||||
53
|
||||
],
|
||||
[
|
||||
258,
|
||||
55
|
||||
],
|
||||
[
|
||||
258,
|
||||
55
|
||||
],
|
||||
[
|
||||
254,
|
||||
62
|
||||
],
|
||||
[
|
||||
254,
|
||||
62
|
||||
],
|
||||
[
|
||||
258,
|
||||
62
|
||||
],
|
||||
[
|
||||
261,
|
||||
62
|
||||
],
|
||||
[
|
||||
263,
|
||||
62
|
||||
],
|
||||
[
|
||||
245,
|
||||
49
|
||||
],
|
||||
[
|
||||
247,
|
||||
49
|
||||
],
|
||||
[
|
||||
252,
|
||||
49
|
||||
],
|
||||
[
|
||||
254,
|
||||
49
|
||||
],
|
||||
[
|
||||
249,
|
||||
51
|
||||
],
|
||||
[
|
||||
247,
|
||||
49
|
||||
],
|
||||
[
|
||||
265,
|
||||
51
|
||||
],
|
||||
[
|
||||
269,
|
||||
51
|
||||
],
|
||||
[
|
||||
272,
|
||||
51
|
||||
],
|
||||
[
|
||||
274,
|
||||
55
|
||||
],
|
||||
[
|
||||
272,
|
||||
55
|
||||
],
|
||||
[
|
||||
267,
|
||||
53
|
||||
],
|
||||
[
|
||||
247,
|
||||
69
|
||||
],
|
||||
[
|
||||
252,
|
||||
66
|
||||
],
|
||||
[
|
||||
254,
|
||||
66
|
||||
],
|
||||
[
|
||||
256,
|
||||
66
|
||||
],
|
||||
[
|
||||
258,
|
||||
66
|
||||
],
|
||||
[
|
||||
263,
|
||||
69
|
||||
],
|
||||
[
|
||||
265,
|
||||
71
|
||||
],
|
||||
[
|
||||
263,
|
||||
73
|
||||
],
|
||||
[
|
||||
258,
|
||||
73
|
||||
],
|
||||
[
|
||||
256,
|
||||
73
|
||||
],
|
||||
[
|
||||
252,
|
||||
73
|
||||
],
|
||||
[
|
||||
249,
|
||||
71
|
||||
],
|
||||
[
|
||||
247,
|
||||
69
|
||||
],
|
||||
[
|
||||
252,
|
||||
66
|
||||
],
|
||||
[
|
||||
256,
|
||||
66
|
||||
],
|
||||
[
|
||||
261,
|
||||
69
|
||||
],
|
||||
[
|
||||
265,
|
||||
71
|
||||
],
|
||||
[
|
||||
261,
|
||||
73
|
||||
],
|
||||
[
|
||||
256,
|
||||
71
|
||||
],
|
||||
[
|
||||
252,
|
||||
71
|
||||
],
|
||||
[
|
||||
249,
|
||||
49
|
||||
],
|
||||
[
|
||||
269,
|
||||
51
|
||||
],
|
||||
[
|
||||
195,
|
||||
262
|
||||
],
|
||||
[
|
||||
206,
|
||||
270
|
||||
],
|
||||
[
|
||||
210,
|
||||
276
|
||||
],
|
||||
[
|
||||
213,
|
||||
280
|
||||
],
|
||||
[
|
||||
216,
|
||||
285
|
||||
],
|
||||
[
|
||||
201,
|
||||
287
|
||||
],
|
||||
[
|
||||
208,
|
||||
294
|
||||
],
|
||||
[
|
||||
213,
|
||||
296
|
||||
],
|
||||
[
|
||||
216,
|
||||
299
|
||||
],
|
||||
[
|
||||
197,
|
||||
289
|
||||
],
|
||||
[
|
||||
206,
|
||||
296
|
||||
],
|
||||
[
|
||||
208,
|
||||
299
|
||||
],
|
||||
[
|
||||
213,
|
||||
299
|
||||
],
|
||||
[
|
||||
195,
|
||||
289
|
||||
],
|
||||
[
|
||||
201,
|
||||
294
|
||||
],
|
||||
[
|
||||
208,
|
||||
296
|
||||
],
|
||||
[
|
||||
208,
|
||||
299
|
||||
],
|
||||
[
|
||||
195,
|
||||
289
|
||||
],
|
||||
[
|
||||
197,
|
||||
294
|
||||
],
|
||||
[
|
||||
201,
|
||||
296
|
||||
],
|
||||
[
|
||||
206,
|
||||
296
|
||||
],
|
||||
[
|
||||
310,
|
||||
265
|
||||
],
|
||||
[
|
||||
304,
|
||||
270
|
||||
],
|
||||
[
|
||||
302,
|
||||
274
|
||||
],
|
||||
[
|
||||
299,
|
||||
279
|
||||
],
|
||||
[
|
||||
297,
|
||||
284
|
||||
],
|
||||
[
|
||||
308,
|
||||
287
|
||||
],
|
||||
[
|
||||
307,
|
||||
292
|
||||
],
|
||||
[
|
||||
304,
|
||||
299
|
||||
],
|
||||
[
|
||||
299,
|
||||
301
|
||||
],
|
||||
[
|
||||
309,
|
||||
287
|
||||
],
|
||||
[
|
||||
308,
|
||||
292
|
||||
],
|
||||
[
|
||||
307,
|
||||
299
|
||||
],
|
||||
[
|
||||
303,
|
||||
301
|
||||
],
|
||||
[
|
||||
310,
|
||||
287
|
||||
],
|
||||
[
|
||||
309,
|
||||
292
|
||||
],
|
||||
[
|
||||
308,
|
||||
298
|
||||
],
|
||||
[
|
||||
307,
|
||||
302
|
||||
],
|
||||
[
|
||||
313,
|
||||
287
|
||||
],
|
||||
[
|
||||
310,
|
||||
291
|
||||
],
|
||||
[
|
||||
309,
|
||||
296
|
||||
],
|
||||
[
|
||||
308,
|
||||
299
|
||||
]
|
||||
]
|
||||
}
|
||||
Reference in New Issue
Block a user