Test angles before
This commit is contained in:
20
ModelUE4.py
20
ModelUE4.py
@@ -45,7 +45,7 @@ def getAngle(avec0, avec1, bvec0, bvec1):
|
||||
znam2 = float(np.sqrt(pow(bvec0, 2) + pow(bvec1, 2)))
|
||||
if (znam1*znam2) == 0:
|
||||
return None
|
||||
return np.arccos(chis / (znam1 * znam2))
|
||||
return np.arccos(chis / (znam1 * znam2)) * 180. / np.pi
|
||||
|
||||
def checkRot(tvec0, tvec1, tvec0_apose, tvec1_apose, rvec_apose):
|
||||
# tvec0 - parent bone by root
|
||||
@@ -490,7 +490,7 @@ def updateValueAPoseWorld(data, dataxyz, parent_name, current_name):
|
||||
data[current_name]["rotation"]["rotx"] = rvec[0]
|
||||
data[current_name]["rotation"]["roty"] = rvec[1]
|
||||
data[current_name]["rotation"]["rotz"] = rvec[2]
|
||||
data[current_name]["visible"] = dataxyz[current_name]
|
||||
data[current_name]["visible"] = dataxyz[current_name][3]
|
||||
|
||||
def bodyconvertwithrot(poseslms, data, coef, maxy):
|
||||
dataxyz = {}
|
||||
@@ -667,12 +667,12 @@ def bodyconvertwithrot(poseslms, data, coef, maxy):
|
||||
updateValueAPoseWorld(data, dataxyz, "clavicle_l", "shoulder_l")
|
||||
updateValueAPoseWorld(data, dataxyz, "spine_05", "clavicle_r")
|
||||
updateValueAPoseWorld(data, dataxyz, "spine_05", "clavicle_l")
|
||||
updateValueAPoseWorld(data, dataxyz, "head", "clavicle_l")
|
||||
updateValueAPoseWorld(data, dataxyz, "spine_05", "head")
|
||||
updateValueAPoseWorld(data, dataxyz, "spine_04", "spine_05")
|
||||
updateValueAPoseWorld(data, dataxyz, "spine_02", "spine_04")
|
||||
updateValueAPoseWorld(data, dataxyz, "pelvis", "spine_02")
|
||||
updateValueAPoseWorld(data, dataxyz, "ankle_l", "ball_l")
|
||||
updateValueAPoseWorld(data, dataxyz, "ball_r", "ankle_r")
|
||||
updateValueAPoseWorld(data, dataxyz, "ankle_r", "ball_r")
|
||||
updateValueAPoseWorld(data, dataxyz, "ankle_l", "heel_l")
|
||||
updateValueAPoseWorld(data, dataxyz, "ankle_r", "heel_r")
|
||||
updateValueAPoseWorld(data, dataxyz, "knee_l", "ankle_l")
|
||||
@@ -877,6 +877,12 @@ def bonetranslation(data, bone_name, tvec):
|
||||
|
||||
def rhandconverttranslation(data):
|
||||
tvec = [data["hand_r"]["translation"]["x"], data["hand_r"]["translation"]["y"], data["hand_r"]["translation"]["z"]]
|
||||
data_apose = {}
|
||||
bodyaposeworld(data_apose)
|
||||
tvec_pose = [data_apose["hand_r"]["translation"]["x"], data_apose["hand_r"]["translation"]["y"], data_apose["hand_r"]["translation"]["z"]]
|
||||
tvec[0] = tvec[0] - tvec_pose[0]
|
||||
tvec[1] = tvec[1] - tvec_pose[1]
|
||||
tvec[2] = tvec[2] - tvec_pose[2]
|
||||
|
||||
bonetranslation(data, "pinky_4_r", tvec)
|
||||
bonetranslation(data, "pinky_3_r", tvec)
|
||||
@@ -897,6 +903,12 @@ def rhandconverttranslation(data):
|
||||
|
||||
def lhandconverttranslation(data):
|
||||
tvec = [data["hand_l"]["translation"]["x"], data["hand_l"]["translation"]["y"], data["hand_l"]["translation"]["z"]]
|
||||
data_apose = {}
|
||||
bodyaposeworld(data_apose)
|
||||
tvec_pose = [data_apose["hand_l"]["translation"]["x"], data_apose["hand_l"]["translation"]["y"], data_apose["hand_l"]["translation"]["z"]]
|
||||
tvec[0] = tvec[0] - tvec_pose[0]
|
||||
tvec[1] = tvec[1] - tvec_pose[1]
|
||||
tvec[2] = tvec[2] - tvec_pose[2]
|
||||
|
||||
bonetranslation(data, "pinky_4_l", tvec)
|
||||
bonetranslation(data, "pinky_3_l", tvec)
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
address_input: "0" # input video path or webcam index
|
||||
|
||||
# Image processing
|
||||
scale_pose: 42.0 # shoulder width
|
||||
scale_pose: 35.4 # shoulder width
|
||||
crop_image: 1.0 # coefficient of image cropping
|
||||
|
||||
# OSC output
|
||||
@@ -18,3 +18,4 @@ show_image: True # show image in opencv interface
|
||||
# Model UE4
|
||||
apose: False # APose coordinates
|
||||
world: True # True - world coordinates, False - local coordinates
|
||||
old_world: False # False - new method of world coordinates with rotations
|
||||
|
||||
@@ -160,7 +160,7 @@ class hpe_mp_class():
|
||||
except Exception as err:
|
||||
logger.exception("Error scaling hpe class: " + str(err))
|
||||
|
||||
def getJSON(self, apose=False, world=True):
|
||||
def getJSON(self, apose=False, world=True, old_world=False):
|
||||
data = {}
|
||||
try:
|
||||
if apose:
|
||||
@@ -180,16 +180,20 @@ class hpe_mp_class():
|
||||
if lm.y > maxy:
|
||||
maxy = lm.y
|
||||
|
||||
# bodyconvert(poseslms, data, self.coef, maxy)
|
||||
bodyconvertwithrot(poseslms, data, self.coef, maxy)
|
||||
if old_world:
|
||||
bodyconvert(poseslms, data, self.coef, maxy)
|
||||
else:
|
||||
bodyconvertwithrot(poseslms, data, self.coef, maxy)
|
||||
|
||||
rhandlms = {}
|
||||
if self.results_hol.right_hand_landmarks:
|
||||
for id, lm in enumerate(self.results_hol.right_hand_landmarks.landmark):
|
||||
rhandlms[id] = lm
|
||||
|
||||
# rhandconvert(rhandlms, data, self.coef)
|
||||
rhandconvertwithrot(rhandlms, data, self.coef)
|
||||
if old_world:
|
||||
rhandconvert(rhandlms, data, self.coef)
|
||||
else:
|
||||
rhandconvertwithrot(rhandlms, data, self.coef)
|
||||
else:
|
||||
rhandconverttranslation(data)
|
||||
|
||||
@@ -198,8 +202,10 @@ class hpe_mp_class():
|
||||
for id, lm in enumerate(self.results_hol.left_hand_landmarks.landmark):
|
||||
lhandlms[id] = lm
|
||||
|
||||
lhandconvert(lhandlms, data, self.coef)
|
||||
lhandconvertwithrot(lhandlms, data, self.coef)
|
||||
if old_world:
|
||||
lhandconvert(lhandlms, data, self.coef)
|
||||
else:
|
||||
lhandconvertwithrot(lhandlms, data, self.coef)
|
||||
else:
|
||||
lhandconverttranslation(data)
|
||||
else:
|
||||
|
||||
@@ -29,6 +29,7 @@ mirror_image = data_yaml["mirror_image"]
|
||||
show_image = data_yaml["show_image"]
|
||||
apose = data_yaml["apose"]
|
||||
world = data_yaml["world"]
|
||||
old_world = data_yaml["old_world"]
|
||||
|
||||
# OSC client
|
||||
client = udp_client.SimpleUDPClient(osc_address, osc_port)
|
||||
@@ -75,12 +76,12 @@ while True:
|
||||
# Output
|
||||
if output_method == 'file':
|
||||
# JSON
|
||||
res = mp_cl.getJSON(apose=apose, world=world)
|
||||
res = mp_cl.getJSON(apose=apose, world=world, old_world=old_world)
|
||||
with open('hierarchy_data.json', 'w', encoding='utf-8') as f:
|
||||
json.dump(res, f, ensure_ascii=False, indent=4)
|
||||
else:
|
||||
# OSC
|
||||
res = mp_cl.getJSON(apose=apose, world=world)
|
||||
res = mp_cl.getJSON(apose=apose, world=world, old_world=old_world)
|
||||
res_list = []
|
||||
for val in res.keys():
|
||||
stroka = str(val)
|
||||
|
||||
Reference in New Issue
Block a user