added backpose adaption, hand shifting, handle missing wrist

This commit is contained in:
Ram Deshmukh
2024-01-08 16:47:59 +05:30
parent 00c4f67a16
commit 4d6ff920bf
7 changed files with 2127 additions and 30 deletions
+181 -27
View File
@@ -874,6 +874,8 @@ 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[109:]) #left hand
canvas = torch.from_numpy(canvas.astype(np.float32)/255.0)[None,]
return (canvas, )
@@ -921,38 +923,59 @@ class TRI3DPoseAdaption:
if similar_torso == False:
canvas = torch.from_numpy(canvas.astype(np.float32)/255.0)[None,]
return (canvas, similar_torso)
#Hands
input_keypoints = comfy_utils.rotate(ref_keypoints, input_keypoints, 2, 3) # rotate left elbow
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
input_keypoints = comfy_utils.rotate(ref_keypoints, input_keypoints, 2, 3) # rotate left elbow
input_keypoints = comfy_utils.scale(ref_keypoints, input_keypoints, 1, 2, 2, 3) #scaling w.r.t to shoulder to elbow ratio of ref pose
prev_lw = input_keypoints[4]
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, 5, 6) #rotate right elbow
#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.rotate(ref_keypoints, input_keypoints, 5, 6) #rotate right elbow
input_keypoints = comfy_utils.scale(ref_keypoints, input_keypoints, 1, 5, 5, 6) #scaling w.r.t to shoulder to elbow ratio of ref pose
prev_rw = input_keypoints[7]
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 = 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
#legs
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, 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, 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, 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
face_points = input_keypoints[14:]
nose = input_keypoints[0]
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
#changing face points to w.r.t to new nose point after rotation
x_off = input_keypoints[0][0] - nose[0]
y_off = input_keypoints[0][1] - nose[1]
for i in range(4):
new_x = face_points[i][0]+x_off
new_y = face_points[i][1]+y_off
input_keypoints[i+14] = [new_x, new_y]
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.scale(ref_keypoints, input_keypoints, 1, 0, 0, 14) #scaling w.r.t to neck len to eye_nose len ratio of ref pose
@@ -967,6 +990,8 @@ class TRI3DPoseAdaption:
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,]
return (canvas, similar_torso)
@@ -997,6 +1022,8 @@ 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,]
else:
canvas = np.zeros(shape=(height, width, 3), dtype=np.uint8)
@@ -1007,21 +1034,145 @@ class TRI3DLoadPoseJson:
# mask = torch.zeros((64,64), dtype=torch.float32, device="cpu")
return (canvas, )
# @classmethod
# def IS_CHANGED(s, image):
# image_path = folder_paths.get_annotated_filepath(image)
# m = hashlib.sha256()
# with open(image_path, 'rb') as f:
# m.update(f.read())
# return m.digest().hex()
class TRI3DBackPoseAdaption:
def __init__(self):
pass
@classmethod
def INPUT_TYPES(s):
return {
"required": {
"input_pose_json_file": ("STRING", {"default": "dwpose/keypoints"}),
"backpose_json_file": ("STRING", {"default": "dwpose/keypoints"}),
"input_pose_type": (["front_pose", "back_pose"], {"default": "back_pose"}),
"target_pose_type":(["normal_back_pose", "side_facing_back_pose"], {"default": "normal_back_pose"})
}
}
RETURN_TYPES = ("IMAGE","BOOLEAN")
FUNCTION = "main"
CATEGORY = "TRI3D"
def main(self, input_pose_json_file, backpose_json_file, input_pose_type, target_pose_type):
from .dwpose import comfy_utils
# @classmethod
# def VALIDATE_INPUTS(s, image):
# if not folder_paths.exists_annotated_filepath(image):
# return "Invalid image file: {}".format(image)
input_pose = json.load(open(input_pose_json_file))
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)
# return True
ref_pose = json.load(open(backpose_json_file))
ref_height = ref_pose['height']
ref_width = ref_pose['width']
ref_keypoints = ref_pose['keypoints']
#check torso similarity
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
if similar_torso == False:
canvas = torch.from_numpy(canvas.astype(np.float32)/255.0)[None,]
return (canvas, similar_torso)
#flip horizontally
if input_pose_type == "front_pose":
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]
for i in range(len(input_keypoints)):
x,y = input_keypoints[i]
if input_keypoints[i] == [-1,-1]: continue
input_keypoints[i] = [input_width - x, 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
input_keypoints = comfy_utils.rotate(ref_keypoints, input_keypoints, 2, 3) # rotate left elbow
input_keypoints = comfy_utils.scale(ref_keypoints, input_keypoints, 1, 2, 2, 3) #scaling w.r.t to shoulder to elbow ratio of ref pose
prev_lw = input_keypoints[4]
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:])
# 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.rotate(ref_keypoints, input_keypoints, 5, 6) #rotate right elbow
input_keypoints = comfy_utils.scale(ref_keypoints, input_keypoints, 1, 5, 5, 6) #scaling w.r.t to shoulder to elbow ratio of ref pose
prev_rw = input_keypoints[7]
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 = 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
#legs
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, 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, 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, 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
if target_pose_type == "normal_back_pose":
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
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
#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])
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[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
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,]
return (canvas, similar_torso)
# A dictionary that contains all nodes you want to export with their names
# NOTE: names should be globally unique
NODE_CLASS_MAPPINGS = {
@@ -1035,10 +1186,12 @@ NODE_CLASS_MAPPINGS = {
"tri3d-dwpose": TRI3DDWPose_Preprocessor,
"tri3d-pose-to-image": TRI3DPosetoImage,
"tri3d-pose-adaption": TRI3DPoseAdaption,
"tri3d-load-pose-json": TRI3DLoadPoseJson
"tri3d-load-pose-json": TRI3DLoadPoseJson,
"tri3d-back-pose-adaption": TRI3DBackPoseAdaption,
}
VERSION = "1.4.0"
VERSION = "1.6.0"
# 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,
@@ -1051,5 +1204,6 @@ NODE_DISPLAY_NAME_MAPPINGS = {
"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-load-pose-json": "Load Pose Json" + " v" + VERSION,
"tri3d-back-pose-adaption": "Back Pose Adaption" + "v" + VERSION
}
+147 -3
View File
@@ -1,6 +1,6 @@
import cv2, os, math, json
import numpy as np
import matplotlib
def draw_bodypose(canvas: np.ndarray, keypoints: list) -> np.ndarray:
@@ -44,6 +44,35 @@ def draw_bodypose(canvas: np.ndarray, keypoints: list) -> np.ndarray:
cv2.circle(canvas, (int(x), int(y)), 4, color, thickness=-1)
return canvas
def draw_handpose(canvas: np.ndarray, keypoints: list) -> np.ndarray:
H, W, _ = canvas.shape
edges = [[0, 1], [1, 2], [2, 3], [3, 4], [0, 5], [5, 6], [6, 7], [7, 8], [0, 9], [9, 10], \
[10, 11], [11, 12], [0, 13], [13, 14], [14, 15], [15, 16], [0, 17], [17, 18], [18, 19], [19, 20]]
for ie, (e1, e2) in enumerate(edges):
k1 = keypoints[e1]
k2 = keypoints[e2]
if k1 is None or k2 is None:
continue
x1 = int(k1[0])
y1 = int(k1[1])
x2 = int(k2[0])
y2 = int(k2[1])
cv2.line(canvas, (x1, y1), (x2, y2), matplotlib.colors.hsv_to_rgb([ie / float(len(edges)), 1.0, 1.0]) * 255, thickness=2)
for keypoint in keypoints:
if keypoint is None:
continue
x, y = keypoint[0], keypoint[1]
x = int(x)
y = int(y)
cv2.circle(canvas, (x, y), 4, (0, 0, 255), thickness=-1)
return canvas
def rotate(src_keypoints, dest_keypoints, point1_idx, point2_idx):
@@ -96,6 +125,97 @@ def scale(src_keypoints, dest_keypoints, ref_point1_idx, ref_point2_idx, point1_
return dest_keypoints
def scale_hand(src_keypoints, dest_keypoints, ref_point1_idx, ref_point2_idx, starting_idx):
"""
scales all 20 hand lines for the given reference wrist length
"""
rotate(src_keypoints, dest_keypoints, 0+starting_idx, 1+starting_idx)
scale(src_keypoints, dest_keypoints, ref_point1_idx, ref_point2_idx, 0+starting_idx, 1+starting_idx)
rotate(src_keypoints, dest_keypoints, 0+starting_idx, 5+starting_idx)
scale(src_keypoints, dest_keypoints, ref_point1_idx, ref_point2_idx, 0+starting_idx, 5+starting_idx)
rotate(src_keypoints, dest_keypoints, 0+starting_idx, 9+starting_idx)
scale(src_keypoints, dest_keypoints, ref_point1_idx, ref_point2_idx, 0+starting_idx, 9+starting_idx)
rotate(src_keypoints, dest_keypoints, 0+starting_idx, 13+starting_idx)
scale(src_keypoints, dest_keypoints, ref_point1_idx, ref_point2_idx, 0+starting_idx, 13+starting_idx)
rotate(src_keypoints, dest_keypoints, 0+starting_idx, 17+starting_idx)
scale(src_keypoints, dest_keypoints, ref_point1_idx, ref_point2_idx, 0+starting_idx, 17+starting_idx)
rotate(src_keypoints, dest_keypoints, 1+starting_idx, 2+starting_idx)
scale(src_keypoints, dest_keypoints, ref_point1_idx, ref_point2_idx, 1+starting_idx, 2+starting_idx)
rotate(src_keypoints, dest_keypoints, 2+starting_idx, 3+starting_idx)
scale(src_keypoints, dest_keypoints, ref_point1_idx, ref_point2_idx, 2+starting_idx, 3+starting_idx)
rotate(src_keypoints, dest_keypoints, 3+starting_idx, 4+starting_idx)
scale(src_keypoints, dest_keypoints, ref_point1_idx, ref_point2_idx, 3+starting_idx, 4+starting_idx)
rotate(src_keypoints, dest_keypoints, 5+starting_idx, 6+starting_idx)
scale(src_keypoints, dest_keypoints, ref_point1_idx, ref_point2_idx, 5+starting_idx, 6+starting_idx)
rotate(src_keypoints, dest_keypoints, 6+starting_idx, 7+starting_idx)
scale(src_keypoints, dest_keypoints, ref_point1_idx, ref_point2_idx, 6+starting_idx, 7+starting_idx)
rotate(src_keypoints, dest_keypoints, 7+starting_idx, 8+starting_idx)
scale(src_keypoints, dest_keypoints, ref_point1_idx, ref_point2_idx, 7+starting_idx, 8+starting_idx)
rotate(src_keypoints, dest_keypoints, 9+starting_idx, 10+starting_idx)
scale(src_keypoints, dest_keypoints, ref_point1_idx, ref_point2_idx, 9+starting_idx, 10+starting_idx)
rotate(src_keypoints, dest_keypoints, 10+starting_idx, 11+starting_idx)
scale(src_keypoints, dest_keypoints, ref_point1_idx, ref_point2_idx, 10+starting_idx, 11+starting_idx)
rotate(src_keypoints, dest_keypoints, 11+starting_idx, 12+starting_idx)
scale(src_keypoints, dest_keypoints, ref_point1_idx, ref_point2_idx, 11+starting_idx, 12+starting_idx)
rotate(src_keypoints, dest_keypoints, 13+starting_idx, 14+starting_idx)
scale(src_keypoints, dest_keypoints, ref_point1_idx, ref_point2_idx, 13+starting_idx, 14+starting_idx)
rotate(src_keypoints, dest_keypoints, 14+starting_idx, 15+starting_idx)
scale(src_keypoints, dest_keypoints, ref_point1_idx, ref_point2_idx, 14+starting_idx, 15+starting_idx)
rotate(src_keypoints, dest_keypoints, 15+starting_idx, 16+starting_idx)
scale(src_keypoints, dest_keypoints, ref_point1_idx, ref_point2_idx, 15+starting_idx, 16+starting_idx)
rotate(src_keypoints, dest_keypoints, 17+starting_idx, 18+starting_idx)
scale(src_keypoints, dest_keypoints, ref_point1_idx, ref_point2_idx, 17+starting_idx, 18+starting_idx)
rotate(src_keypoints, dest_keypoints, 18+starting_idx, 19+starting_idx)
scale(src_keypoints, dest_keypoints, ref_point1_idx, ref_point2_idx, 18+starting_idx, 19+starting_idx)
rotate(src_keypoints, dest_keypoints, 19+starting_idx, 20+starting_idx)
scale(src_keypoints, dest_keypoints, ref_point1_idx, ref_point2_idx, 19+starting_idx, 20+starting_idx)
return dest_keypoints
def rotate_hand(src_keypoints, dest_keypoints, starting_idx):
"""
scales all 20 hand lines for the given reference wrist length
src_keypoints: ref keypoints
dest_keypoints: mannequin keypoints
starting_idx: starting index of hand
"""
rotate(src_keypoints, dest_keypoints, 0+starting_idx, 1+starting_idx)
rotate(src_keypoints, dest_keypoints, 0+starting_idx, 5+starting_idx)
rotate(src_keypoints, dest_keypoints, 0+starting_idx, 9+starting_idx)
rotate(src_keypoints, dest_keypoints, 0+starting_idx, 13+starting_idx)
rotate(src_keypoints, dest_keypoints, 0+starting_idx, 17+starting_idx)
rotate(src_keypoints, dest_keypoints, 1+starting_idx, 2+starting_idx)
rotate(src_keypoints, dest_keypoints, 2+starting_idx, 3+starting_idx)
rotate(src_keypoints, dest_keypoints, 3+starting_idx, 4+starting_idx)
rotate(src_keypoints, dest_keypoints, 5+starting_idx, 6+starting_idx)
rotate(src_keypoints, dest_keypoints, 6+starting_idx, 7+starting_idx)
rotate(src_keypoints, dest_keypoints, 7+starting_idx, 8+starting_idx)
rotate(src_keypoints, dest_keypoints, 9+starting_idx, 10+starting_idx)
rotate(src_keypoints, dest_keypoints, 10+starting_idx, 11+starting_idx)
rotate(src_keypoints, dest_keypoints, 11+starting_idx, 12+starting_idx)
rotate(src_keypoints, dest_keypoints, 13+starting_idx, 14+starting_idx)
rotate(src_keypoints, dest_keypoints, 14+starting_idx, 15+starting_idx)
rotate(src_keypoints, dest_keypoints, 15+starting_idx, 16+starting_idx)
rotate(src_keypoints, dest_keypoints, 17+starting_idx, 18+starting_idx)
rotate(src_keypoints, dest_keypoints, 18+starting_idx, 19+starting_idx)
rotate(src_keypoints, dest_keypoints, 19+starting_idx, 20+starting_idx)
return dest_keypoints
def get_torso_angles(keypoints):
"""
Function to get torso angles
@@ -117,7 +237,31 @@ def get_torso_angles(keypoints):
bi = [int((a[0]+c[0])/2), int((a[1]+c[1])/2)]
#calculatng angle with y axis
angle_radians = math.atan((bi[1]-b[1])/(bi[0]-b[0]))
angle_radians = math.atan2((bi[1]-b[1]),(bi[0]-b[0]))
torso_angle = 90 - abs(math.degrees(angle_radians))
return ls_angle, rs_angle, torso_angle
return ls_angle, rs_angle, torso_angle
def move(prev_point, new_point, dependent_points):
"""e.g if wrist is moved then rest of the hand points also be moved by same offset where """
x_off = new_point[0] - prev_point[0]
y_off = (new_point[1] - prev_point[1])
for i in range(len(dependent_points)):
if dependent_points[i] == [-1,-1]: continue
dependent_points[i] = [dependent_points[i][0]+x_off, dependent_points[i][1]+y_off]
return dependent_points
def switch_to_backpose(input_keypoints, input_width):
"""for the given straight pose flip horizontally """
for i in range(len(input_keypoints)):
if i in [0,14,15]:
input_keypoints[i] = [-1, -1]
continue
x,y = input_keypoints[i]
input_keypoints[i] = [input_width - x, y]
return input_keypoints
+526
View File
@@ -0,0 +1,526 @@
{
"height": 512,
"width": 512,
"keypoints": [
[
-1,
-1
],
[
264,
125
],
[
298,
125
],
[
310,
193
],
[
314,
254
],
[
230,
125
],
[
216,
192
],
[
211,
252
],
[
286,
244
],
[
292,
339
],
[
294,
448
],
[
240,
247
],
[
242,
336
],
[
246,
444
],
[
-1,
-1
],
[
-1,
-1
],
[
246,
74
],
[
279,
74
],
[
240,
66
],
[
240,
72
],
[
240,
76
],
[
242,
82
],
[
242,
86
],
[
246,
88
],
[
248,
92
],
[
252,
94
],
[
258,
94
],
[
262,
94
],
[
266,
94
],
[
270,
92
],
[
274,
90
],
[
276,
86
],
[
278,
82
],
[
280,
78
],
[
282,
74
],
[
248,
58
],
[
250,
56
],
[
252,
56
],
[
256,
56
],
[
260,
56
],
[
268,
58
],
[
272,
58
],
[
274,
60
],
[
278,
62
],
[
280,
64
],
[
264,
64
],
[
262,
66
],
[
262,
68
],
[
262,
68
],
[
258,
74
],
[
258,
74
],
[
262,
74
],
[
264,
74
],
[
266,
74
],
[
250,
62
],
[
252,
62
],
[
256,
62
],
[
258,
62
],
[
254,
64
],
[
252,
62
],
[
268,
64
],
[
272,
64
],
[
274,
64
],
[
276,
68
],
[
274,
68
],
[
270,
66
],
[
252,
80
],
[
256,
78
],
[
258,
78
],
[
260,
78
],
[
262,
78
],
[
266,
80
],
[
268,
82
],
[
266,
84
],
[
262,
84
],
[
260,
84
],
[
256,
84
],
[
254,
82
],
[
252,
80
],
[
256,
78
],
[
260,
78
],
[
264,
80
],
[
268,
82
],
[
264,
84
],
[
260,
82
],
[
256,
82
],
[
254,
62
],
[
272,
64
],
[
211,
255
],
[
221,
262
],
[
226,
268
],
[
229,
272
],
[
232,
278
],
[
217,
279
],
[
223,
286
],
[
229,
288
],
[
232,
291
],
[
214,
281
],
[
221,
288
],
[
223,
291
],
[
229,
291
],
[
211,
281
],
[
217,
286
],
[
223,
288
],
[
223,
291
],
[
211,
281
],
[
214,
286
],
[
217,
288
],
[
221,
288
],
[
314.2191598676356,
257
],
[
308.2191598676356,
262
],
[
306.2191598676356,
266
],
[
303.2191598676356,
270
],
[
301.2191598676356,
276
],
[
312.2191598676356,
279
],
[
311.2191598676356,
284
],
[
308.2191598676356,
290
],
[
303.2191598676356,
292
],
[
313.2191598676356,
279
],
[
312.2191598676356,
284
],
[
311.2191598676356,
290
],
[
307.2191598676356,
292
],
[
314.2191598676356,
279
],
[
313.2191598676356,
284
],
[
312.2191598676356,
289
],
[
311.2191598676356,
293
],
[
317.2191598676356,
279
],
[
314.2191598676356,
283
],
[
313.2191598676356,
287
],
[
312.2191598676356,
290
]
]
}
@@ -0,0 +1,220 @@
{
"last_node_id": 423,
"last_link_id": 674,
"nodes": [
{
"id": 394,
"type": "tri3d-back-pose-adaption",
"pos": [
2654,
-135
],
"size": {
"0": 315,
"1": 150
},
"flags": {},
"order": 0,
"mode": 0,
"inputs": [],
"outputs": [
{
"name": "IMAGE",
"type": "IMAGE",
"links": [
658
],
"shape": 3,
"slot_index": 0
},
{
"name": "BOOLEAN",
"type": "BOOLEAN",
"links": null,
"shape": 3
}
],
"properties": {
"Node name for S&R": "tri3d-back-pose-adaption"
},
"widgets_values": [
"C:\\tri3d\\pose_library\\testing\\Database\\dump_folder2\\mannequin.json",
"C:\\tri3d\\pose_library\\testing\\backpose\\backpose.json",
"front_pose",
"normal_back_pose"
]
},
{
"id": 391,
"type": "tri3d-pose-to-image",
"pos": [
2984,
-266
],
"size": [
210,
58
],
"flags": {},
"order": 1,
"mode": 0,
"outputs": [
{
"name": "IMAGE",
"type": "IMAGE",
"links": [
656
],
"shape": 3,
"slot_index": 0
}
],
"properties": {
"Node name for S&R": "tri3d-pose-to-image"
},
"widgets_values": [
"C:\\tri3d\\pose_library\\testing\\Database\\dump_folder2\\mannequin.json"
]
},
{
"id": 393,
"type": "tri3d-pose-to-image",
"pos": [
3206,
-269
],
"size": [
228.55314621582056,
58
],
"flags": {},
"order": 2,
"mode": 0,
"outputs": [
{
"name": "IMAGE",
"type": "IMAGE",
"links": [
657
],
"shape": 3,
"slot_index": 0
}
],
"properties": {
"Node name for S&R": "tri3d-pose-to-image"
},
"widgets_values": [
"C:\\tri3d\\pose_library\\testing\\backpose\\backpose.json"
]
},
{
"id": 390,
"type": "PreviewImage",
"pos": [
2997,
-175
],
"size": {
"0": 210,
"1": 246
},
"flags": {},
"order": 4,
"mode": 0,
"inputs": [
{
"name": "images",
"type": "IMAGE",
"link": 656
}
],
"title": "Mannequin pose",
"properties": {
"Node name for S&R": "PreviewImage"
}
},
{
"id": 395,
"type": "PreviewImage",
"pos": [
3430,
-180
],
"size": {
"0": 170.9424591064453,
"1": 246
},
"flags": {},
"order": 3,
"mode": 0,
"inputs": [
{
"name": "images",
"type": "IMAGE",
"link": 658
}
],
"title": "adapted pose",
"properties": {
"Node name for S&R": "PreviewImage"
}
},
{
"id": 392,
"type": "PreviewImage",
"pos": [
3213,
-172
],
"size": {
"0": 210,
"1": 246
},
"flags": {},
"order": 5,
"mode": 0,
"inputs": [
{
"name": "images",
"type": "IMAGE",
"link": 657
}
],
"title": "ref backpose",
"properties": {
"Node name for S&R": "PreviewImage"
}
}
],
"links": [
[
656,
391,
0,
390,
0,
"IMAGE"
],
[
657,
393,
0,
392,
0,
"IMAGE"
],
[
658,
394,
0,
395,
0,
"IMAGE"
]
],
"groups": [],
"config": {},
"extra": {},
"version": 0.4
}
@@ -0,0 +1,526 @@
{
"height": 512,
"width": 512,
"keypoints": [
[
234,
85
],
[
264,
125
],
[
298,
125
],
[
310,
193
],
[
314,
254
],
[
230,
125
],
[
216,
192
],
[
211,
252
],
[
286,
244
],
[
292,
339
],
[
294,
448
],
[
240,
247
],
[
242,
336
],
[
246,
444
],
[
-1,
-1
],
[
238,
72
],
[
-1,
-1
],
[
262,
70
],
[
212,
82
],
[
212,
88
],
[
212,
92
],
[
214,
98
],
[
214,
102
],
[
218,
104
],
[
220,
108
],
[
224,
110
],
[
230,
110
],
[
234,
110
],
[
238,
110
],
[
242,
108
],
[
246,
106
],
[
248,
102
],
[
250,
98
],
[
252,
94
],
[
254,
90
],
[
220,
74
],
[
222,
72
],
[
224,
72
],
[
228,
72
],
[
232,
72
],
[
240,
74
],
[
244,
74
],
[
246,
76
],
[
250,
78
],
[
252,
80
],
[
236,
80
],
[
234,
82
],
[
232,
84
],
[
255,
85
],
[
230,
90
],
[
230,
90
],
[
234,
90
],
[
236,
90
],
[
238,
90
],
[
222,
78
],
[
224,
78
],
[
228,
78
],
[
230,
78
],
[
226,
80
],
[
224,
78
],
[
240,
80
],
[
244,
80
],
[
246,
80
],
[
248,
84
],
[
246,
84
],
[
242,
82
],
[
224,
96
],
[
228,
94
],
[
230,
94
],
[
232,
94
],
[
234,
94
],
[
238,
96
],
[
240,
98
],
[
238,
100
],
[
234,
100
],
[
232,
100
],
[
228,
100
],
[
226,
98
],
[
224,
96
],
[
228,
94
],
[
232,
94
],
[
236,
96
],
[
240,
98
],
[
236,
100
],
[
232,
98
],
[
228,
98
],
[
226,
78
],
[
244,
80
],
[
211,
255
],
[
221,
262
],
[
226,
268
],
[
229,
272
],
[
232,
278
],
[
217,
279
],
[
223,
286
],
[
229,
288
],
[
232,
291
],
[
214,
281
],
[
221,
288
],
[
223,
291
],
[
229,
291
],
[
211,
281
],
[
217,
286
],
[
223,
288
],
[
223,
291
],
[
211,
281
],
[
214,
286
],
[
217,
288
],
[
221,
288
],
[
314,
257
],
[
308,
262
],
[
306,
266
],
[
303,
270
],
[
301,
276
],
[
312,
279
],
[
311,
284
],
[
308,
290
],
[
303,
292
],
[
313,
279
],
[
312,
284
],
[
311,
290
],
[
307,
292
],
[
314,
279
],
[
313,
284
],
[
312,
289
],
[
311,
293
],
[
317,
279
],
[
314,
283
],
[
313,
287
],
[
312,
290
]
]
}
File diff suppressed because one or more lines are too long
@@ -0,0 +1,526 @@
{
"height": 512,
"width": 512,
"keypoints": [
[
298,
85
],
[
264,
125
],
[
298,
125
],
[
310,
193
],
[
314,
254
],
[
230,
125
],
[
216,
192
],
[
211,
252
],
[
286,
244
],
[
292,
339
],
[
294,
448
],
[
240,
247
],
[
242,
336
],
[
246,
444
],
[
293.3658724790831,
75
],
[
-1,
-1
],
[
270.3658724790831,
73
],
[
-1,
-1
],
[
276.3658724790831,
82
],
[
276.3658724790831,
88
],
[
276.3658724790831,
92
],
[
278.3658724790831,
98
],
[
278.3658724790831,
102
],
[
282.3658724790831,
104
],
[
284.3658724790831,
108
],
[
288.3658724790831,
110
],
[
294.3658724790831,
110
],
[
298.3658724790831,
110
],
[
302.3658724790831,
110
],
[
306.3658724790831,
108
],
[
310.3658724790831,
106
],
[
312.3658724790831,
102
],
[
314.3658724790831,
98
],
[
316.3658724790831,
94
],
[
318.3658724790831,
90
],
[
284.3658724790831,
74
],
[
286.3658724790831,
72
],
[
288.3658724790831,
72
],
[
292.3658724790831,
72
],
[
296.3658724790831,
72
],
[
304.3658724790831,
74
],
[
308.3658724790831,
74
],
[
310.3658724790831,
76
],
[
314.3658724790831,
78
],
[
316.3658724790831,
80
],
[
300.3658724790831,
80
],
[
298.3658724790831,
82
],
[
296.3658724790831,
84
],
[
319.3658724790831,
85
],
[
294.3658724790831,
90
],
[
294.3658724790831,
90
],
[
298.3658724790831,
90
],
[
300.3658724790831,
90
],
[
302.3658724790831,
90
],
[
286.3658724790831,
78
],
[
288.3658724790831,
78
],
[
292.3658724790831,
78
],
[
294.3658724790831,
78
],
[
290.3658724790831,
80
],
[
288.3658724790831,
78
],
[
304.3658724790831,
80
],
[
308.3658724790831,
80
],
[
310.3658724790831,
80
],
[
312.3658724790831,
84
],
[
310.3658724790831,
84
],
[
306.3658724790831,
82
],
[
288.3658724790831,
96
],
[
292.3658724790831,
94
],
[
294.3658724790831,
94
],
[
296.3658724790831,
94
],
[
298.3658724790831,
94
],
[
302.3658724790831,
96
],
[
304.3658724790831,
98
],
[
302.3658724790831,
100
],
[
298.3658724790831,
100
],
[
296.3658724790831,
100
],
[
292.3658724790831,
100
],
[
290.3658724790831,
98
],
[
288.3658724790831,
96
],
[
292.3658724790831,
94
],
[
296.3658724790831,
94
],
[
300.3658724790831,
96
],
[
304.3658724790831,
98
],
[
300.3658724790831,
100
],
[
296.3658724790831,
98
],
[
292.3658724790831,
98
],
[
290.3658724790831,
78
],
[
308.3658724790831,
80
],
[
211,
255
],
[
221,
262
],
[
226,
268
],
[
229,
272
],
[
232,
278
],
[
217,
279
],
[
223,
286
],
[
229,
288
],
[
232,
291
],
[
214,
281
],
[
221,
288
],
[
223,
291
],
[
229,
291
],
[
211,
281
],
[
217,
286
],
[
223,
288
],
[
223,
291
],
[
211,
281
],
[
214,
286
],
[
217,
288
],
[
221,
288
],
[
314,
257
],
[
308,
262
],
[
306,
266
],
[
303,
270
],
[
301,
276
],
[
312,
279
],
[
311,
284
],
[
308,
290
],
[
303,
292
],
[
313,
279
],
[
312,
284
],
[
311,
290
],
[
307,
292
],
[
314,
279
],
[
313,
284
],
[
312,
289
],
[
311,
293
],
[
317,
279
],
[
314,
283
],
[
313,
287
],
[
312,
290
]
]
}