uv conversion ready for skirts

This commit is contained in:
2022-09-29 15:45:13 +00:00
parent fa8f24f0c5
commit e3e7087c10
+38 -35
View File
@@ -448,24 +448,27 @@ def test(verts, faces, values):
if __name__ == '__main__': if __name__ == '__main__':
parser = argparse.ArgumentParser() parser = argparse.ArgumentParser()
parser.add_argument("-f", "--folder", help = "end of range") parser.add_argument("-f", "--folder", help = "end of range", default='/home/workspace/data/dataset/train_skirt_25_2')
parser.add_argument("-s", "--start", help = "start of range") parser.add_argument("-s", "--start", help = "start of range", default=0)
parser.add_argument("-e", "--end", help = "end of range") parser.add_argument("-e", "--end", help = "end of range", default=10)
parser.add_argument("-n", "--name", help = "end of range") parser.add_argument("-n", "--name", help = "end of range", default='lhunor')
parser.add_argument("-sk", "--skirt", help = "end of range", default=1)
args = parser.parse_args() args = parser.parse_args()
# smpl = SMPL('FeatureLines/superSMPL') # smpl = SMPL('FeatureLines/superSMPL')
print("skirt" if args.skirt == 1 else "not skirt")
# F = np.load("D:\\Work\\Code\\featurelines\\FeatureLines\\superSMPL\\smpl_faces.npy") # F = np.load("D:\\Work\\Code\\featurelines\\FeatureLines\\superSMPL\\smpl_faces.npy")
F = np.load("custom_utils/smpl_faces.npy") F = np.load("custom_utils/smpl_faces" + ("_skirt" if args.skirt == 1 else "") + ".npy")
# data = np.load("Blender/uv_data_1.npz", allow_pickle=True) # data = np.load("Blender/uv_data_1.npz", allow_pickle=True)
# uv_faces = data.f.Ft # uv_faces = data.f.Ft
# folder = 'Z:\\Work\\Huni\\Barcelona\\Dataset\\train' # folder = 'Z:\\Work\\Huni\\Barcelona\\Dataset\\train'
folder = args.folder folder = args.folder
uv_map = np.load('custom_utils/stretched_uv_map_3.npy') uv_map = np.load('custom_utils/stretched_uv_map_' + ("skirt" if args.skirt == 1 else "3") + '.npy')
m2uv = np.load('custom_utils/m2uv.npy', allow_pickle=True).item() m2uv = np.load('custom_utils/m2uv' + ("_skirt" if args.skirt == 1 else "") + '.npy', allow_pickle=True).item()
m2uv = m2uv_array(m2uv) m2uv = m2uv_array(m2uv)
uv_mask = np.load('custom_utils/mask_256x512.npy') uv_mask = np.load('custom_utils/mask_256x512' + ("_skirt" if args.skirt == 1 else "") + '.npy')
curvature_label_type = '6_25' curvature_label_type = '6_25'
uv_res = 256 uv_res = 256
@@ -525,13 +528,13 @@ if __name__ == '__main__':
mask = np.squeeze(sio.loadmat(os.path.join(garment_dir, garment + '_mask.mat'))['mask'].astype(bool)) mask = np.squeeze(sio.loadmat(os.path.join(garment_dir, garment + '_mask.mat'))['mask'].astype(bool))
# body = readPC2(os.path.join(folder, id, 'Body_posed.pc16'), True)['V'] # body = readPC2(os.path.join(folder, id, 'Body_posed.pc16'), True)['V']
gt = readPC2(os.path.join(folder, id, garment + '_registered.pc16'), True)['V'] gt = readPC2(os.path.join(folder, id, garment + '_registered.pc16'), True)['V']
# curvature = np.load(os.path.join(folder, id, 'curvature_label_' + curvature_label_type + '.npy')) curvature = np.load(os.path.join(folder, id, 'curvature_label_' + curvature_label_type + '.npy'))
# mesh_unposed = [np.load(os.path.join(folder, id, 'mesh_unposed', id + '_' + str(i) + '.npz')) for i in range(gt.shape[0])] mesh_unposed = [np.load(os.path.join(folder, id, 'mesh_unposed', id + '_' + str(i) + '.npz')) for i in range(gt.shape[0])]
# mesh_unposed = np.stack([mesh_unposed[i]['mesh_unposed'] for i in range(gt.shape[0])]) mesh_unposed = np.stack([mesh_unposed[i]['mesh_unposed'] for i in range(gt.shape[0])])
mesh_unposed_no_shape = [np.load(os.path.join(folder, id, 'mesh_unposed_no_shape', id + '_' + str(i) + '.npz')) for i in range(gt.shape[0])] mesh_unposed_no_shape = [np.load(os.path.join(folder, id, 'mesh_unposed_no_shape', id + '_' + str(i) + '.npz')) for i in range(gt.shape[0])]
mesh_unposed_no_shape = np.stack([mesh_unposed_no_shape[i]['mesh_unposed_no_shape'] for i in range(gt.shape[0])]) mesh_unposed_no_shape = np.stack([mesh_unposed_no_shape[i]['mesh_unposed_no_shape'] for i in range(gt.shape[0])])
body_no_orient = [np.load(os.path.join(folder, id, 'mesh_posed_body_no_orient', id + '_' + str(i) + '.npz')) for i in range(gt.shape[0])] # body_no_orient = [np.load(os.path.join(folder, id, 'mesh_posed_body_no_orient', id + '_' + str(i) + '.npz')) for i in range(gt.shape[0])]
body_no_orient = np.stack([body_no_orient[i]['mesh_posed_body_no_orient'] for i in range(gt.shape[0])]) # body_no_orient = np.stack([body_no_orient[i]['mesh_posed_body_no_orient'] for i in range(gt.shape[0])])
verts_static = (body_static + offsets_static) # * mask[:, np.newaxis] verts_static = (body_static + offsets_static) # * mask[:, np.newaxis]
@@ -601,42 +604,42 @@ if __name__ == '__main__':
uv_verts_static = uv_verts_static.astype(np.float32) uv_verts_static = uv_verts_static.astype(np.float32)
# uv_body_static = convert_to_uv(uv_res, m2uv, uv_map, body_static, neighbours=3, mask=None, method='rbf', garment_uv_mask=None).astype(np.float32) # uv_body_static = convert_to_uv(uv_res, m2uv, uv_map, body_static, neighbours=3, mask=None, method='rbf', garment_uv_mask=None).astype(np.float32)
# uv_body = convert_to_uv_batch(uv_res, m2uv, uv_map, body[:, :, :], neighbours=3, mask=None, method='rbf', garment_uv_mask=None, garment_uv_mask_border=garment_uv_mask_border).astype(np.float32) # uv_body = convert_to_uv_batch(uv_res, m2uv, uv_map, body[:, :, :], neighbours=3, mask=None, method='rbf', garment_uv_mask=None, garment_uv_mask_border=garment_uv_mask_border).astype(np.float32)
uv_posed_body_no_orient = convert_to_uv_batch(uv_res, m2uv, uv_map, body_no_orient[:, :, :], neighbours=3, mask=None, method='rbf', garment_uv_mask=None, garment_uv_mask_border=garment_uv_mask_border).astype(np.float32) # uv_posed_body_no_orient = convert_to_uv_batch(uv_res, m2uv, uv_map, body_no_orient[:, :, :], neighbours=3, mask=None, method='rbf', garment_uv_mask=None, garment_uv_mask_border=garment_uv_mask_border).astype(np.float32)
# uv_gt = convert_to_uv_batch(uv_res, m2uv, uv_map, gt[:, :, :], neighbours=3, mask=mask, method='rbf', garment_uv_mask=garment_uv_mask, garment_uv_mask_border=garment_uv_mask_border).astype(np.float32) uv_gt = convert_to_uv_batch(uv_res, m2uv, uv_map, gt[:, :, :], neighbours=3, mask=mask, method='rbf', garment_uv_mask=garment_uv_mask, garment_uv_mask_border=garment_uv_mask_border).astype(np.float32)
# uv_curvature = convert_to_uv_batch_label(uv_res, m2uv, uv_map, curvature[:, :], neighbours=3, mask=mask, method='nearest', garment_uv_mask=garment_uv_mask, garment_uv_mask_border=garment_uv_mask_border).astype(np.float32) uv_curvature = convert_to_uv_batch_label(uv_res, m2uv, uv_map, curvature[:, :], neighbours=3, mask=mask, method='nearest', garment_uv_mask=garment_uv_mask, garment_uv_mask_border=garment_uv_mask_border).astype(np.float32)
# uv_unposed = convert_to_uv_batch(uv_res, m2uv, uv_map, mesh_unposed[:, :, :], neighbours=3, mask=mask, method='rbf', garment_uv_mask=garment_uv_mask, garment_uv_mask_border=garment_uv_mask_border).astype(np.float32) uv_unposed = convert_to_uv_batch(uv_res, m2uv, uv_map, mesh_unposed[:, :, :], neighbours=3, mask=mask, method='rbf', garment_uv_mask=garment_uv_mask, garment_uv_mask_border=garment_uv_mask_border).astype(np.float32)
# uv_unposed_no_shape = convert_to_uv_batch(uv_res, m2uv, uv_map, mesh_unposed_no_shape[:, :, :], neighbours=3, mask=mask, method='rbf', garment_uv_mask=garment_uv_mask, garment_uv_mask_border=garment_uv_mask_border).astype(np.float32) uv_unposed_no_shape = convert_to_uv_batch(uv_res, m2uv, uv_map, mesh_unposed_no_shape[:, :, :], neighbours=3, mask=mask, method='rbf', garment_uv_mask=garment_uv_mask, garment_uv_mask_border=garment_uv_mask_border).astype(np.float32)
# uv_shaped_body = convert_to_uv(uv_res, m2uv, uv_map, shaped_body, neighbours=3, mask=None, method='rbf', garment_uv_mask=None).astype(np.float32) # uv_shaped_body = convert_to_uv(uv_res, m2uv, uv_map, shaped_body, neighbours=3, mask=None, method='rbf', garment_uv_mask=None).astype(np.float32)
print(time.perf_counter() - start) print(time.perf_counter() - start)
start = time.perf_counter() start = time.perf_counter()
# np.save(os.path.join(folder, id, garment + '_offsets_static_uv.npy'), uv_verts_static) np.save(os.path.join(folder, id, garment + '_offsets_static_uv.npy'), uv_verts_static)
# np.save(os.path.join(folder, id, 'body_static_uv.npy'), uv_body_static) # np.save(os.path.join(folder, id, 'body_static_uv.npy'), uv_body_static)
# np.save(os.path.join(folder, id, 'mask_uv.npy'), garment_uv_mask) np.save(os.path.join(folder, id, 'mask_uv.npy'), garment_uv_mask)
# os.makedirs(os.path.join(folder, id, 'body_posed_uv'), exist_ok=True) # os.makedirs(os.path.join(folder, id, 'body_posed_uv'), exist_ok=True)
# for i in range(uv_body.shape[0]): # for i in range(uv_body.shape[0]):
# np.savez_compressed(os.path.join(folder, id, 'body_posed_uv', garment + '_' + str(i) + '.npz'), uv_body=uv_body[i, :, :, :]) # np.savez_compressed(os.path.join(folder, id, 'body_posed_uv', garment + '_' + str(i) + '.npz'), uv_body=uv_body[i, :, :, :])
os.makedirs(os.path.join(folder, id, 'uv_posed_body_no_orient'), exist_ok=True) # os.makedirs(os.path.join(folder, id, 'uv_posed_body_no_orient'), exist_ok=True)
for i in range(uv_posed_body_no_orient.shape[0]): # for i in range(uv_posed_body_no_orient.shape[0]):
np.savez_compressed(os.path.join(folder, id, 'uv_posed_body_no_orient', garment + '_' + str(i) + '.npz'), uv_posed_body_no_orient=uv_posed_body_no_orient[i, :, :, :]) # np.savez_compressed(os.path.join(folder, id, 'uv_posed_body_no_orient', garment + '_' + str(i) + '.npz'), uv_posed_body_no_orient=uv_posed_body_no_orient[i, :, :, :])
# os.makedirs(os.path.join(folder, id, 'gt_uv'), exist_ok=True) os.makedirs(os.path.join(folder, id, 'gt_uv'), exist_ok=True)
# for i in range(uv_gt.shape[0]): for i in range(uv_gt.shape[0]):
# np.savez_compressed(os.path.join(folder, id, 'gt_uv', garment + '_' + str(i) + '.npz'), uv_gt=uv_gt[i, :, :, :]) np.savez_compressed(os.path.join(folder, id, 'gt_uv', garment + '_' + str(i) + '.npz'), uv_gt=uv_gt[i, :, :, :])
# os.makedirs(os.path.join(folder, id, 'curvature_uv'), exist_ok=True) os.makedirs(os.path.join(folder, id, 'curvature_uv'), exist_ok=True)
# for i in range(uv_curvature.shape[0]): for i in range(uv_curvature.shape[0]):
# np.savez_compressed(os.path.join(folder, id, 'curvature_uv', garment + '_' + str(i) + '.npz'), curvature_uv=uv_curvature[i, :, :]) np.savez_compressed(os.path.join(folder, id, 'curvature_uv', garment + '_' + str(i) + '.npz'), curvature_uv=uv_curvature[i, :, :])
# os.makedirs(os.path.join(folder, id, 'uv_unposed'), exist_ok=True) os.makedirs(os.path.join(folder, id, 'uv_unposed'), exist_ok=True)
# for i in range(uv_unposed.shape[0]): for i in range(uv_unposed.shape[0]):
# np.savez_compressed(os.path.join(folder, id, 'uv_unposed', garment + '_' + str(i) + '.npz'), uv_unposed=uv_unposed[i, :, :, :]) np.savez_compressed(os.path.join(folder, id, 'uv_unposed', garment + '_' + str(i) + '.npz'), uv_unposed=uv_unposed[i, :, :, :])
# os.makedirs(os.path.join(folder, id, 'uv_unposed_no_shape'), exist_ok=True) os.makedirs(os.path.join(folder, id, 'uv_unposed_no_shape'), exist_ok=True)
# for i in range(uv_unposed_no_shape.shape[0]): for i in range(uv_unposed_no_shape.shape[0]):
# np.savez_compressed(os.path.join(folder, id, 'uv_unposed_no_shape', garment + '_' + str(i) + '.npz'), uv_unposed_no_shape=uv_unposed_no_shape[i, :, :, :]) np.savez_compressed(os.path.join(folder, id, 'uv_unposed_no_shape', garment + '_' + str(i) + '.npz'), uv_unposed_no_shape=uv_unposed_no_shape[i, :, :, :])
# os.makedirs(os.path.join(folder, id, 'uv_shaped_body'), exist_ok=True) # os.makedirs(os.path.join(folder, id, 'uv_shaped_body'), exist_ok=True)