1、EDGE预测 52维 blendershape结果,制作csv 输出数据
import random
import shutil,glob
import pandas as pd
import numpy as np
import model.save_csv as save_csv
random.seed(1234)
col = ['Timecode', 'BlendShapeCount', 'EyeBlinkLeft', 'EyeLookDownLeft',
'EyeLookInLeft', 'EyeLookOutLeft', 'EyeLookUpLeft', 'EyeSquintLeft',
'EyeWideLeft', 'EyeBlinkRight', 'EyeLookDownRight', 'EyeLookInRight',
'EyeLookOutRight', 'EyeLookUpRight', 'EyeSquintRight', 'EyeWideRight',
'JawForward', 'JawRight', 'JawLeft', 'JawOpen', 'MouthClose',
'MouthFunnel', 'MouthPucker', 'MouthRight', 'MouthLeft',
'MouthSmileLeft', 'MouthSmileRight', 'MouthFrownLeft',
'MouthFrownRight', 'MouthDimpleLeft', 'MouthDimpleRight',
'MouthStretchLeft', 'MouthStretchRight', 'MouthRollLower',
'MouthRollUpper', 'MouthShrugLower', 'MouthShrugUpper',
'MouthPressLeft', 'MouthPressRight', 'MouthLowerDownLeft',
'MouthLowerDownRight', 'MouthUpperUpLeft', 'MouthUpperUpRight',
'BrowDownLeft', 'BrowDownRight', 'BrowInnerUp', 'BrowOuterUpLeft',
'BrowOuterUpRight', 'CheekPuff', 'CheekSquintLeft', 'CheekSquintRight',
'NoseSneerLeft', 'NoseSneerRight', 'TongueOut', 'HeadYaw', 'HeadPitch',
'HeadRoll', 'LeftEyeYaw', 'LeftEyePitch', 'LeftEyeRoll', 'RightEyeYaw',
'RightEyePitch', 'RightEyeRoll']
def mean_pixels(data):
out = []
data = data.T
for d in data:
d = np.array(d)
window_size = 4
sma = np.convolve(d, np.ones(window_size) / window_size, mode='valid')
out.append(sma.tolist())
return data.T
def increment_time(steps, step_size=2):
start_time_str = '01:01:01:02'
# # 将时间字符串分割为时、分、秒、毫秒部分
hours, minutes, seconds, milliseconds_str = start_time_str.split(':')
hours, minutes, seconds, milliseconds = int(hours), int(minutes), int(seconds), int(milliseconds_str)
res = []
for _ in range(steps):
milliseconds += step_size # 递增毫秒数
# 更新秒、分和小时(如果需要)
seconds_total = milliseconds / 60. # 总秒数
if seconds_total >= 1:
milliseconds = milliseconds - 60
seconds += 1
secondsa = seconds / 60. # 总秒数
if secondsa >= 1:
seconds = seconds - 60
minutes += 1
minutesa = minutes / 60. # 总秒数
if minutesa >= 1:
minutes = minutes - 60
hours += 1
str_time = '{}:{}:{}:{}.312'.format(str(hours).zfill(2),str(minutes).zfill(2),str(seconds).zfill(2),str(milliseconds).zfill(2))
res.append(str_time)
return res
def csv_saveall(verticesa,output):
vertices = verticesa
time_list = increment_time(vertices.shape[0])
outdata = np.zeros((vertices.shape[0],len(col)))
outdata[:,2:54] = vertices
df = pd.DataFrame(columns=col,data=outdata)
df[col[0]] = time_list
df[col[1]] = [16] * vertices.shape[0]
df.to_csv(output + '.csv', index=False) # index=False表示不保存行索引
def csv_save(verticesa, output,epoch):
# if epoch == 'test':
# out_data = []
# last_list = []
# for i in range(len(verticesa)):
# dd = verticesa[i]
# ban = int(len(dd) / 2)
# if len(out_data) == 0:
# out_data = dd[:ban, :]
# last_list = dd[ban:, :]
# else:
# now_list = (dd[:ban, :] + last_list) / 2
# out_data = np.concatenate((out_data, now_list), axis=0)
# last_list = dd[ban:, :]
# verticesa = np.array(out_data)
# (n,52) 数据
vertices = verticesa
# 制作开始时间
time_list = increment_time(vertices.shape[0])
# 制作数据值 本代码值预测了 2-54 的值,其余值为0
outdata = np.zeros((vertices.shape[0], len(col)))
outdata[:, 2:54] = mean_pixels(vertices)
# 保存 csv
df = pd.DataFrame(columns=col, data=outdata)
df[col[0]] = time_list
df[col[1]] = [16] * vertices.shape[0]
df.to_csv(output, index=False) # index=False表示不保存行索引
if __name__ == '__main__':
csv_save()