1 Commits
Author SHA1 Message Date
aravind 79f7e55440 Added oneformer mask 2024-02-01 12:47:01 +05:30
+429 -178
View File
@@ -7,6 +7,10 @@ import comfy.model_management as model_management
import folder_paths
from PIL import Image, ImageOps
from transformers import AutoProcessor
from transformers import OneFormerForUniversalSegmentation
from transformers import OneFormerProcessor
def from_torch_image(image):
image = image.squeeze().cpu().numpy() * 255.0
@@ -53,6 +57,30 @@ def do_work_with_mask(image, mask, external_file_name):
return image
def get_segmentation_of_person(image):
NAME_MODEL_ONEFORMER = 'shi-labs/oneformer_ade20k_dinat_large'
processor = OneFormerProcessor.from_pretrained(NAME_MODEL_ONEFORMER)
model = OneFormerForUniversalSegmentation.from_pretrained(
NAME_MODEL_ONEFORMER)
width = image.shape[1]
height = image.shape[0]
inputs = processor(image, ["semantic"], return_tensors="pt")
with torch.no_grad():
outputs = model(**inputs)
predicted_semantic_map = processor.post_process_semantic_segmentation(
outputs, target_sizes=[(height, width)])[0]
img = predicted_semantic_map.detach().cpu().numpy()
img = (img == 12)
img = img.astype(np.uint8) * 255
return img
class TRI3DATRParseBatch:
def __init__(self):
@@ -1089,8 +1117,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 +1158,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, )
@@ -1166,7 +1196,8 @@ 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):
from .dwpose import comfy_utils
if image_angle == "front":
@@ -1175,7 +1206,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 +1226,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 +1403,58 @@ 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': '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 +1462,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 +1684,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 +1808,7 @@ class FloatToImage:
return image
class TRI3D_recolor_LAB:
@classmethod
@@ -1981,8 +2179,6 @@ class TRI3D_recolor:
return image_output
class TRI3D_image_mask_2_box:
def __init__(self):
@@ -2036,6 +2232,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 +2259,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 +2276,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 +2286,37 @@ class TRI3D_clipdrop_bgremove_api:
# print(mask.shape)
return output,
class TRI3D_oneformer_person_mask:
def __init__(self):
pass
@classmethod
def INPUT_TYPES(s):
return {
"required": {
"image": ("IMAGE", ),
},
}
FUNCTION = "run"
RETURN_TYPES = ("IMAGE", )
CATEGORY = "tri3d"
def run(self, image):
image = from_torch_image(image)
image_final = np.zeros((image.shape[0], image.shape[1], 4),
dtype=np.uint8)
image_final[:, :, 0:3] = image
image = get_segmentation_of_person(image)
image_final[:, :, 3] = image[:, :]
image = to_torch_image(image_final)
return image
# A dictionary that contains all nodes you want to export with their names
# NOTE: names should be globally unique
NODE_CLASS_MAPPINGS = {
@@ -2107,31 +2338,51 @@ 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-oneformer-person-mask": TRI3D_oneformer_person_mask,
}
VERSION = "2.3"
# 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,
'tri3d-extract-parts-batch': 'Extract Parts Batch' + " v" + VERSION,
'tri3d-extract-parts-batch2': 'Extract Parts Batch 2' + " v" + VERSION,
"tri3d-position-parts-batch": "Position Parts Batch" + " v" + VERSION,
"tri3d-swap-pixels": "Swap Pixels by Mask" + " v" + VERSION,
"tri3d-atr-parse-batch":
"ATR Parse Batch" + " v" + VERSION,
'tri3d-extract-parts-batch':
'Extract Parts Batch' + " v" + VERSION,
'tri3d-extract-parts-batch2':
'Extract Parts Batch 2' + " v" + VERSION,
"tri3d-position-parts-batch":
"Position Parts Batch" + " v" + VERSION,
"tri3d-swap-pixels":
"Swap Pixels by Mask" + " v" + VERSION,
"tri3d-skin-feathered-padded-mask":
"Skin Feathered Padded Mask" + " v" + VERSION,
"tri3d-interaction-canny":
"Garment Skin Interaction Canny" + " v" + VERSION,
"tri3d-dwpose": "DWPose" + " v" + VERSION,
"tri3d-pose-to-image": "Pose to Image" + " v" + VERSION,
"tri3d-pose-adaption": "Pose Adaption" + " v" + VERSION,
"tri3d-load-pose-json": "Load Pose Json" + " v" + VERSION,
"tri3d-face-recognise": "Recognise face" + " v" + VERSION,
"tri3d-float-to-image": "Render float" + " v" + VERSION,
"tri3d-recolor-mask": "Recolor mask HSV space" + " v" + VERSION,
"tri3d-recolor-mask-LAB_space": "Recolor mask LAB space" + " v" + VERSION,
"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-dwpose":
"DWPose" + " v" + VERSION,
"tri3d-pose-to-image":
"Pose to Image" + " v" + VERSION,
"tri3d-pose-adaption":
"Pose Adaption" + " v" + VERSION,
"tri3d-load-pose-json":
"Load Pose Json" + " v" + VERSION,
"tri3d-face-recognise":
"Recognise face" + " v" + VERSION,
"tri3d-float-to-image":
"Render float" + " v" + VERSION,
"tri3d-recolor-mask":
"Recolor mask HSV space" + " v" + VERSION,
"tri3d-recolor-mask-LAB_space":
"Recolor mask LAB space" + " v" + VERSION,
"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-oneformer-person-mask":
"Get person mask using oneformer" + " v" + VERSION,
}