only read info.mat once
This commit is contained in:
+8
-12
@@ -57,16 +57,14 @@ class DataReader:
|
|||||||
- V: human mesh vertices
|
- V: human mesh vertices
|
||||||
- F: mesh faces
|
- F: mesh faces
|
||||||
"""
|
"""
|
||||||
def read_human(self, sample, frame, absolute=True):
|
def read_human(self, sample, frame, trans, zrot):
|
||||||
# Read sample data
|
|
||||||
info = self.read_info(sample)
|
|
||||||
# SMPL parameters
|
# SMPL parameters
|
||||||
gender, pose, shape, trans = self.read_smpl_params(sample, frame)
|
gender, pose, shape, trans = self.read_smpl_params(sample, frame)
|
||||||
# Compute SMPL
|
# 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]
|
V -= J[0:1]
|
||||||
# Apply rotation on z-axis
|
# 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,:]
|
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 """
|
""" Garment data """
|
||||||
@@ -76,21 +74,19 @@ class DataReader:
|
|||||||
- sample: name of the sample
|
- sample: name of the sample
|
||||||
- garment: type of garment (e.g.: 'Tshirt', 'Jumpsuit', ...)
|
- garment: type of garment (e.g.: 'Tshirt', 'Jumpsuit', ...)
|
||||||
- frame: frame number
|
- 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:
|
Outputs:
|
||||||
- V: 3D vertex locations for the specified sample, garment and frame
|
- 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)
|
# Read garment vertices (relative to root joint)
|
||||||
pc16_path = os.path.join(self.SRC, sample, garment + '_registered.pc16')
|
pc16_path = os.path.join(self.SRC, sample, garment + '_registered.pc16')
|
||||||
V = readPC2Frame(pc16_path, frame, True)
|
V = readPC2Frame(pc16_path, frame, True)
|
||||||
# Read sample data
|
# Read sample data
|
||||||
info = self.read_info(sample)
|
if trans is not None:
|
||||||
if absolute:
|
|
||||||
# Transform to absolute
|
# Transform to absolute
|
||||||
V += info['trans'][:,frame][None]
|
V += trans[None]
|
||||||
# Apply rotation on z-axis
|
zRot = zRotMatrix(zrot)
|
||||||
zRot = zRotMatrix(info['zrot'])
|
|
||||||
return zRot.dot(V.T).T
|
return zRot.dot(V.T).T
|
||||||
|
|
||||||
"""
|
"""
|
||||||
|
|||||||
+6
-6
@@ -43,22 +43,22 @@ class Dataset(Dataset):
|
|||||||
def __getitem__(self, idx):
|
def __getitem__(self, idx):
|
||||||
frame : Frame = self.frames[idx]
|
frame : Frame = self.frames[idx]
|
||||||
path = os.path.join(self.folder, frame.id)
|
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 = 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 = 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_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'))
|
mesh_mask = np.load(os.path.join(path, frame.garment + '_mask.npy'))
|
||||||
# TODO: what's the difference between masking and reading .obj file
|
# TODO: what's the difference between masking and reading .obj file
|
||||||
faces = mask_faces(self.body_faces, mesh_mask)
|
faces = mask_faces(self.body_faces, mesh_mask)
|
||||||
# faces = quads2tris(self.reader.read_garment_topology(frame.id, frame.garment))
|
# 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 = 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, 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_no_trans, _, _, _, _ = self.reader.read_human(frame.id, frame.frame_nr, absolute=False)
|
||||||
body_faces = quads2tris(body_faces)
|
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 = 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')
|
combined_faces = torch.Tensor(np.concatenate((body_faces, faces + body.shape[0]))).to('cuda')
|
||||||
|
|
||||||
idx_frame = 35500
|
idx_frame = 35500
|
||||||
|
|||||||
Reference in New Issue
Block a user