saving stl instead of plotting
This commit is contained in:
+54
-46
@@ -144,30 +144,43 @@ def curvature_example(mesh_curvature, uv_curvature, posed, faces, mask):
|
||||
def plot_upscaling(uv_low, uv_high, uv_mask_low, uv_mask_high, faces, color, mask):
|
||||
uv2mesh = UV2Mesh(res=256)
|
||||
model = Upscaler(low_res=32, kernel_size=3)
|
||||
load_model(model, 'checkpoints/32_512_4')
|
||||
load_model(model, 'checkpoints/iccv/iccv_32_2')
|
||||
enhanced = model([uv_low[np.newaxis,:,:,:], uv_mask_low[np.newaxis,:,:]], training=False)[0].numpy()
|
||||
|
||||
bad = tf.image.resize(uv_low, size=(512, 256), method=tf.image.ResizeMethod.LANCZOS5).numpy()
|
||||
good = tf.image.resize(enhanced, size=(512, 256), method=tf.image.ResizeMethod.LANCZOS5).numpy()
|
||||
bad = tf.image.resize(uv_low, size=(512, 256), method=tf.image.ResizeMethod.BILINEAR).numpy()
|
||||
good = tf.image.resize(enhanced, size=(512, 256), method=tf.image.ResizeMethod.BILINEAR).numpy()
|
||||
|
||||
plot = custom_imshow((bad+1)/2 * uv_mask_high[:,:,np.newaxis])
|
||||
plot.write_image('examples/' + type + '_' + id_str + '_' + frame_nr + '_uv_upscale_bad.png')
|
||||
plot = custom_imshow((good+1)/2 * uv_mask_high[:,:,np.newaxis])
|
||||
plot.write_image('examples/' + type + '_' + id_str + '_' + frame_nr + '_uv_upscale_good.png')
|
||||
plot = custom_imshow((uv_high+1)/2 * uv_mask_high[:,:,np.newaxis])
|
||||
plot.write_image('examples/' + type + '_' + id_str + '_' + frame_nr + '_uv_upscale_orig.png')
|
||||
plot = custom_imshow((uv_low+1)/2)
|
||||
plot.write_image('examples/' + type + '_' + id_str + '_' + frame_nr + '_uv_low.png')
|
||||
# plot = custom_imshow((bad+1)/2 * uv_mask_high[:,:,np.newaxis])
|
||||
# plot.write_image('examples/' + type + '_' + id_str + '_' + frame_nr + '_uv_upscale_bad.png')
|
||||
# plot = custom_imshow((good+1)/2 * uv_mask_high[:,:,np.newaxis])
|
||||
# plot.write_image('examples/' + type + '_' + id_str + '_' + frame_nr + '_uv_upscale_good.png')
|
||||
# plot = custom_imshow((uv_high+1)/2 * uv_mask_high[:,:,np.newaxis])
|
||||
# plot.write_image('examples/' + type + '_' + id_str + '_' + frame_nr + '_uv_upscale_orig.png')
|
||||
# plot = custom_imshow((uv_low+1)/2)
|
||||
# plot.write_image('examples/' + type + '_' + id_str + '_' + frame_nr + '_uv_low.png')
|
||||
|
||||
fig = plot_fixed(uv2mesh(bad[np.newaxis,:,:,:])[0].numpy()[mask, :], faces, color)
|
||||
fig.write_image('examples/' + type + '_' + id_str + '_' + frame_nr + '_mesh_upscale_bad.png')
|
||||
fig = plot_fixed(uv2mesh(good[np.newaxis,:,:,:])[0].numpy()[mask, :], faces, color)
|
||||
fig.write_image('examples/' + type + '_' + id_str + '_' + frame_nr + '_mesh_upscale_good.png')
|
||||
fig = plot_fixed(uv2mesh(uv_high[np.newaxis,:,:,:])[0].numpy()[mask, :], faces, color)
|
||||
fig.write_image('examples/' + type + '_' + id_str + '_' + frame_nr + '_mesh_upscale_orig.png')
|
||||
# fig = plot_fixed(uv2mesh(bad[np.newaxis,:,:,:])[0].numpy()[mask, :], faces, color)
|
||||
# fig.write_image('examples/' + type + '_' + id_str + '_' + frame_nr + '_mesh_upscale_bad.png')
|
||||
# fig = plot_fixed(uv2mesh(good[np.newaxis,:,:,:])[0].numpy()[mask, :], faces, color)
|
||||
# fig.write_image('examples/' + type + '_' + id_str + '_' + frame_nr + '_mesh_upscale_good.png')
|
||||
# fig = plot_fixed(uv2mesh(uv_high[np.newaxis,:,:,:])[0].numpy()[mask, :], faces, color)
|
||||
# fig.write_image('examples/' + type + '_' + id_str + '_' + frame_nr + '_mesh_upscale_orig.png')
|
||||
|
||||
save_stl(f'temp/iccv/{id_str}_{frame_nr}_mesh_upscale_bad.stl', uv2mesh(bad[np.newaxis,:,:,:])[0].numpy()[mask, :], faces)
|
||||
save_stl(f'temp/iccv/{id_str}_{frame_nr}_mesh_upscale_good.stl', uv2mesh(good[np.newaxis,:,:,:])[0].numpy()[mask, :], faces)
|
||||
|
||||
print()
|
||||
|
||||
from stl import mesh as mesh_stl
|
||||
|
||||
def save_stl(file, mesh, faces):
|
||||
obj = mesh_stl.Mesh(np.zeros(faces.shape[0], dtype=mesh_stl.Mesh.dtype))
|
||||
for i, f in enumerate(faces):
|
||||
for j in range(3):
|
||||
obj.vectors[i][j] = mesh[f[j],:]
|
||||
|
||||
obj.save(file)
|
||||
|
||||
if __name__ == '__main__':
|
||||
|
||||
uv2mesh = UV2Mesh()
|
||||
@@ -205,7 +218,8 @@ if __name__ == '__main__':
|
||||
do_repeat=False,
|
||||
resolutions=[512, 32],
|
||||
# frames_file='/home/workspace/data/dataset/test_ready/frames_pose_cluster_20_sample_10.txt',
|
||||
frames_file='/home/workspace/data/dataset/test_ready/frames_00438_146.txt',
|
||||
# frames_file='/home/workspace/data/dataset/test_ready/frames_00438_146.txt',
|
||||
frames_file='/home/workspace/data/dataset/test_ready/frames_00228_137.txt',
|
||||
)
|
||||
static_dataset = StaticDataset(folder='/home/workspace/data/dataset/test_ready',
|
||||
resolutions=[512, 32],
|
||||
@@ -261,34 +275,28 @@ if __name__ == '__main__':
|
||||
|
||||
# m = tm.Trimesh(x, faces, process=False, validate=False, vertex_colors=colors)
|
||||
|
||||
x = posed
|
||||
x_1 = unposed.copy()
|
||||
x_1[:, 0] = x_1[:, 0] + 0.75
|
||||
x_2 = unposed_shaped.copy()
|
||||
x_2[:, 0] = x_2[:, 0] + 1.75
|
||||
garments = np.concatenate((x, x_1, x_2), axis=0)
|
||||
all_faces = np.concatenate((faces_garment, faces_garment + x.shape[0], faces_garment + 2*x.shape[0]), axis=0).astype(np.int32)
|
||||
mesh = garments
|
||||
faces = all_faces
|
||||
fig = go.Figure()
|
||||
fig.add_trace(go.Mesh3d(
|
||||
x=mesh[:,0],
|
||||
y=mesh[:,2],
|
||||
z=mesh[:,1],
|
||||
i = faces[:,0],
|
||||
j = faces[:,1],
|
||||
k = faces[:,2],
|
||||
text="",
|
||||
lighting={ 'ambient':0.8, 'diffuse':0.5, 'roughness':0.5 },
|
||||
# x = posed
|
||||
# x_1 = unposed.copy()
|
||||
# x_1[:, 0] = x_1[:, 0] + 0.75
|
||||
# x_2 = unposed_shaped.copy()
|
||||
# x_2[:, 0] = x_2[:, 0] + 1.75
|
||||
# garments = np.concatenate((x, x_1, x_2), axis=0)
|
||||
# all_faces = np.concatenate((faces_garment, faces_garment + x.shape[0], faces_garment + 2*x.shape[0]), axis=0).astype(np.int32)
|
||||
# mesh = garments
|
||||
# faces = all_faces
|
||||
# fig = go.Figure()
|
||||
# fig.add_trace(go.Mesh3d(
|
||||
# x=mesh[:,0],
|
||||
# y=mesh[:,2],
|
||||
# z=mesh[:,1],
|
||||
# i = faces[:,0],
|
||||
# j = faces[:,1],
|
||||
# k = faces[:,2],
|
||||
# text="",
|
||||
# lighting={ 'ambient':0.8, 'diffuse':0.5, 'roughness':0.5 },
|
||||
|
||||
),)
|
||||
fig.show()
|
||||
from stl import mesh as mesh_stl
|
||||
obj = mesh_stl.Mesh(np.zeros(faces.shape[0], dtype=mesh_stl.Mesh.dtype))
|
||||
for i, f in enumerate(faces):
|
||||
for j in range(3):
|
||||
obj.vectors[i][j] = mesh[f[j],:]
|
||||
write_obj_2('temp/blender_test_2.obj', garments, all_faces)
|
||||
# ),)
|
||||
# fig.show()
|
||||
|
||||
|
||||
# fig = plot_fixed(x, faces, colors)
|
||||
@@ -304,6 +312,6 @@ if __name__ == '__main__':
|
||||
|
||||
# uv_mapping_example(body, F, colors[:14475, :], np.ones((14475), bool))
|
||||
# curvature_example(batch['mesh_curvature'][0].numpy(), uv_curvature, posed, faces_garment, mask)
|
||||
# plot_upscaling(batch['uv_unposed_32'].numpy()[0], batch['uv_unposed'].numpy()[0], batch['uv_mask_32'].numpy()[0], batch['uv_mask'].numpy()[0], faces_garment, colors_garment, mask)
|
||||
plot_upscaling(batch['uv_unposed_32'].numpy()[0], batch['uv_unposed'].numpy()[0], batch['uv_mask_32'].numpy()[0], batch['uv_mask'].numpy()[0], faces_garment, colors_garment, mask)
|
||||
|
||||
print()
|
||||
Reference in New Issue
Block a user