TakashiKAWAMOTO-TTS commited on
Commit
2e34547
·
1 Parent(s): dea5ada

use Open3D as headless

Browse files
Files changed (1) hide show
  1. app.py +10 -11
app.py CHANGED
@@ -8,7 +8,6 @@ import os
8
  from types import SimpleNamespace
9
 
10
  DEBUG = False # True: skip gradio and execute in main function
11
- DEBUG_LOG = True
12
 
13
  def process_point_cloud(file_obj):
14
  # Save uploaded file temporarily
@@ -28,17 +27,17 @@ def process_point_cloud(file_obj):
28
  # Estimate normals for visualization
29
  downsampled.estimate_normals()
30
 
31
- # Visualize to image
32
- vis = o3d.visualization.Visualizer()
33
- vis.create_window(visible=False)
34
- vis.add_geometry(downsampled)
35
- vis.poll_events()
36
- vis.update_renderer()
37
- img = vis.capture_screen_float_buffer(True)
38
- vis.destroy_window()
 
39
 
40
- # Convert image to numpy and return
41
- img_np = (255 * np.asarray(img)).astype(np.uint8)
42
  return img_np
43
 
44
  iface = gr.Interface(
 
8
  from types import SimpleNamespace
9
 
10
  DEBUG = False # True: skip gradio and execute in main function
 
11
 
12
  def process_point_cloud(file_obj):
13
  # Save uploaded file temporarily
 
27
  # Estimate normals for visualization
28
  downsampled.estimate_normals()
29
 
30
+ points = np.asarray(downsampled.points)
31
+ fig = plt.figure(figsize=(6, 6))
32
+ ax = fig.add_subplot(111, projection='3d')
33
+ ax.scatter(points[:, 0], points[:, 1], points[:, 2], s=0.5, c='b')
34
+ ax.axis('off')
35
+ plt.tight_layout()
36
+ temp_img_path = os.path.join(tempfile.gettempdir(), "rendered.png")
37
+ plt.savefig(temp_img_path, dpi=150)
38
+ plt.close()
39
 
40
+ img_np = plt.imread(temp_img_path)
 
41
  return img_np
42
 
43
  iface = gr.Interface(