lemonaddie commited on
Commit
cdc8365
1 Parent(s): 3aa29b2

Update app_recon.py

Browse files
Files changed (1) hide show
  1. app_recon.py +20 -4
app_recon.py CHANGED
@@ -35,7 +35,7 @@ from rembg import remove
35
  from segment_anything import sam_model_registry, SamPredictor
36
  from datetime import datetime
37
  import time
38
-
39
 
40
  import sys
41
  sys.path.append("../")
@@ -181,7 +181,16 @@ def reconstruction(image, files):
181
  _, surface, _, _, _ = bilateral_normal_integration_function(normal_np, mask_output_temp, k=2, K=None, max_iter=100, tol=1e-4, cg_max_iter=5000, cg_tol=1e-3)
182
  ply_path = os.path.join(dir_name, f"{name_base}_recon.ply")
183
  surface.save(ply_path, binary=False)
184
- return ply_path, masked_image
 
 
 
 
 
 
 
 
 
185
 
186
  def run_demo():
187
 
@@ -279,7 +288,7 @@ def run_demo():
279
 
280
  with gr.Row():
281
  with gr.Column():
282
- masked_image = gr.Image(interactive=False, label="Masked foreground.")
283
  with gr.Column():
284
  reconstructed_3d = gr.Model3D(
285
  label = 'Bini post-processed 3D model', height=320, interactive=False,
@@ -290,7 +299,14 @@ def run_demo():
290
  # interactive=False,
291
  # )
292
 
 
 
 
 
 
 
293
 
 
294
  run_btn.click(fn=depth_normal,
295
  inputs=[input_image, denoising_steps,
296
  ensemble_size,
@@ -301,7 +317,7 @@ def run_demo():
301
  )
302
  recon_btn.click(fn=reconstruction,
303
  inputs=[input_image, files],
304
- outputs=[reconstructed_3d, masked_image]
305
  )
306
  demo.queue().launch(share=True, max_threads=80)
307
 
 
35
  from segment_anything import sam_model_registry, SamPredictor
36
  from datetime import datetime
37
  import time
38
+ import trimesh
39
 
40
  import sys
41
  sys.path.append("../")
 
181
  _, surface, _, _, _ = bilateral_normal_integration_function(normal_np, mask_output_temp, k=2, K=None, max_iter=100, tol=1e-4, cg_max_iter=5000, cg_tol=1e-3)
182
  ply_path = os.path.join(dir_name, f"{name_base}_recon.ply")
183
  surface.save(ply_path, binary=False)
184
+
185
+ obj_path = ply_path.replace('ply', 'obj')
186
+ mesh = trimesh.load(ply_path)
187
+ T2 = np.array([[0, 1, 0, 0], [1, 0, 0, 0], [0, 0, 1, 0], [0, 0, 0, 1]])
188
+ mesh.apply_transform(T2)
189
+ mesh.export(obj_path)
190
+
191
+ torch.cuda.empty_cache()
192
+
193
+ return obj_path, masked_image, [ply_path]
194
 
195
  def run_demo():
196
 
 
288
 
289
  with gr.Row():
290
  with gr.Column():
291
+ masked_image = gr.Image(interactive=False, height=320, label="Masked foreground.")
292
  with gr.Column():
293
  reconstructed_3d = gr.Model3D(
294
  label = 'Bini post-processed 3D model', height=320, interactive=False,
 
299
  # interactive=False,
300
  # )
301
 
302
+ with gr.Row():
303
+ reconstructed_file = gr.Files(
304
+ label = "3D Mesh (plyfile)",
305
+ elem_id = "download",
306
+ interactive=False,
307
+ )
308
 
309
+
310
  run_btn.click(fn=depth_normal,
311
  inputs=[input_image, denoising_steps,
312
  ensemble_size,
 
317
  )
318
  recon_btn.click(fn=reconstruction,
319
  inputs=[input_image, files],
320
+ outputs=[reconstructed_3d, masked_image, reconstructed_file]
321
  )
322
  demo.queue().launch(share=True, max_threads=80)
323