Stable-X commited on
Commit
803e3ed
1 Parent(s): 3717f04

fix: Refactor visualization

Browse files
Files changed (1) hide show
  1. spann3r/tools/vis.py +15 -25
spann3r/tools/vis.py CHANGED
@@ -14,41 +14,31 @@ import numpy as np
14
  import imageio
15
  import os.path as osp
16
 
17
- def render_frames(pts_all, image_all, camera_parameters, output_dir, mask=None, save_video=True, save_camera=True):
18
- t, h, w, _ = pts_all.shape
19
-
20
  vis = o3d.visualization.Visualizer()
21
- vis.create_window(width=1920, height=1080)
 
22
 
23
  render_frame_path = os.path.join(output_dir, 'render_frames')
 
24
  os.makedirs(render_frame_path, exist_ok=True)
25
-
26
- if save_camera:
27
- o3d.io.write_pinhole_camera_parameters(os.path.join(render_frame_path, 'camera.json'), camera_parameters)
28
 
29
  video_path = os.path.join(output_dir, 'render_frame.mp4')
30
  if save_video:
31
  writer = imageio.get_writer(video_path, fps=10)
32
 
33
- pcd = o3d.geometry.PointCloud()
34
- vis.add_geometry(pcd)
35
-
36
- for i in range(t):
37
- new_pts = pts_all[i].reshape(-1, 3)
38
- new_colors = image_all[i].reshape(-1, 3)
39
-
40
- if mask is not None:
41
- new_pts = new_pts[mask[i].reshape(-1)]
42
- new_colors = new_colors[mask[i].reshape(-1)]
43
-
44
- pcd.points.extend(o3d.utility.Vector3dVector(new_pts))
45
- pcd.colors.extend(o3d.utility.Vector3dVector(new_colors))
46
-
47
- vis.clear_geometries()
48
- vis.add_geometry(pcd)
49
 
 
 
 
50
  ctr = vis.get_view_control()
51
- ctr.convert_from_pinhole_camera_parameters(camera_parameters)
 
 
 
 
52
 
53
  opt = vis.get_render_option()
54
  opt.point_size = 1
@@ -70,7 +60,7 @@ def render_frames(pts_all, image_all, camera_parameters, output_dir, mask=None,
70
  writer.close()
71
 
72
  vis.destroy_window()
73
-
74
 
75
 
76
  def find_render_cam(pcd):
 
14
  import imageio
15
  import os.path as osp
16
 
17
+ def render_frames(o3d_geometry, camera_all, output_dir, save_video=True, save_camera=True):
 
 
18
  vis = o3d.visualization.Visualizer()
19
+ w, h = camera_all[0].intrinsic.width, camera_all[0].intrinsic.height
20
+ vis.create_window(width=w, height=h)
21
 
22
  render_frame_path = os.path.join(output_dir, 'render_frames')
23
+ render_camera_path = os.path.join(output_dir, 'render_cameras')
24
  os.makedirs(render_frame_path, exist_ok=True)
25
+ os.makedirs(render_camera_path, exist_ok=True)
 
 
26
 
27
  video_path = os.path.join(output_dir, 'render_frame.mp4')
28
  if save_video:
29
  writer = imageio.get_writer(video_path, fps=10)
30
 
31
+ vis.add_geometry(o3d_geometry)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
32
 
33
+ for i, camera_params in enumerate(camera_all):
34
+ if camera_params is None:
35
+ continue
36
  ctr = vis.get_view_control()
37
+ ctr.convert_from_pinhole_camera_parameters(camera_params, True)
38
+
39
+ if save_camera:
40
+ o3d.io.write_pinhole_camera_parameters(os.path.join(render_camera_path, f'camera_{i:03d}.json'),
41
+ camera_params)
42
 
43
  opt = vis.get_render_option()
44
  opt.point_size = 1
 
60
  writer.close()
61
 
62
  vis.destroy_window()
63
+ return video_path
64
 
65
 
66
  def find_render_cam(pcd):