only read info.mat once

This commit is contained in:
2023-01-06 11:27:13 +00:00
parent 022c488180
commit 3c2c851ba5
2 changed files with 14 additions and 18 deletions
+8 -12
View File
@@ -57,16 +57,14 @@ class DataReader:
- V: human mesh vertices
- F: mesh faces
"""
def read_human(self, sample, frame, absolute=True):
# Read sample data
info = self.read_info(sample)
def read_human(self, sample, frame, trans, zrot):
# SMPL parameters
gender, pose, shape, trans = self.read_smpl_params(sample, frame)
# Compute SMPL
V, J = self.smpl[gender].set_params(pose=pose, beta=shape, trans=trans if absolute else None)
V, J = self.smpl[gender].set_params(pose=pose, beta=shape, trans=trans)
V -= J[0:1]
# Apply rotation on z-axis
zRot = zRotMatrix(info['zrot'])
zRot = zRotMatrix(zrot)
return zRot.dot(V.T).T, self.smpl[gender].faces, zRot.dot(trans.T).T[None,:], zRot.dot((J - J[0:1] + trans[None,:]).T).T[None,:], zRot.dot((J - J[0:1]).T).T[None,:]
""" Garment data """
@@ -76,21 +74,19 @@ class DataReader:
- sample: name of the sample
- garment: type of garment (e.g.: 'Tshirt', 'Jumpsuit', ...)
- frame: frame number
- absolute: True for absolute vertex locations, False for locations relative to SMPL root joint
- TODO: absolute: True for absolute vertex locations, False for locations relative to SMPL root joint
Outputs:
- V: 3D vertex locations for the specified sample, garment and frame
"""
def read_garment_vertices(self, sample, garment, frame, absolute=True):
def read_garment_vertices(self, sample, garment, frame, trans, zrot):
# Read garment vertices (relative to root joint)
pc16_path = os.path.join(self.SRC, sample, garment + '_registered.pc16')
V = readPC2Frame(pc16_path, frame, True)
# Read sample data
info = self.read_info(sample)
if absolute:
if trans is not None:
# Transform to absolute
V += info['trans'][:,frame][None]
# Apply rotation on z-axis
zRot = zRotMatrix(info['zrot'])
V += trans[None]
zRot = zRotMatrix(zrot)
return zRot.dot(V.T).T
"""
+6 -6
View File
@@ -43,22 +43,22 @@ class Dataset(Dataset):
def __getitem__(self, idx):
frame : Frame = self.frames[idx]
path = os.path.join(self.folder, frame.id)
info = self.reader.read_info(frame.id)
# mesh_posed = readPC2Frame(os.path.join(path, frame.garment + '_registered.pc16'), frame.frame_nr, True)
mesh_posed = self.reader.read_garment_vertices(frame.id, frame.garment, frame.frame_nr)
mesh_posed_no_trans = self.reader.read_garment_vertices(frame.id, frame.garment, frame.frame_nr, absolute=False)
mesh_posed = self.reader.read_garment_vertices(frame.id, frame.garment, frame.frame_nr, info['trans'][:,frame.frame_nr], info['zrot'])
# mesh_posed_no_trans = self.reader.read_garment_vertices(frame.id, frame.garment, frame.frame_nr, absolute=False)
mesh_mask = np.load(os.path.join(path, frame.garment + '_mask.npy'))
# TODO: what's the difference between masking and reading .obj file
faces = mask_faces(self.body_faces, mesh_mask)
# faces = quads2tris(self.reader.read_garment_topology(frame.id, frame.garment))
# body = readPC2Frame(os.path.join(path, 'Body_posed.pc16'), frame.frame_nr, True)
body, body_faces, root_joint, joints, joints_no_trans = self.reader.read_human(frame.id, frame.frame_nr)
body_no_trans, _, _, _, _ = self.reader.read_human(frame.id, frame.frame_nr, absolute=False)
body, body_faces, root_joint, joints, joints_no_trans = self.reader.read_human(frame.id, frame.frame_nr, info['trans'][:,frame.frame_nr], info['zrot'])
# body_no_trans, _, _, _, _ = self.reader.read_human(frame.id, frame.frame_nr, absolute=False)
body_faces = quads2tris(body_faces)
info = self.reader.read_info(frame.id)
combined = torch.Tensor(np.concatenate((body, mesh_posed[mesh_mask, :]))).to('cuda')
combined_no_trans = torch.Tensor(np.concatenate((body_no_trans, mesh_posed_no_trans[mesh_mask, :]))).to('cuda')
# combined_no_trans = torch.Tensor(np.concatenate((body_no_trans, mesh_posed_no_trans[mesh_mask, :]))).to('cuda')
combined_faces = torch.Tensor(np.concatenate((body_faces, faces + body.shape[0]))).to('cuda')
idx_frame = 35500