ostapagon commited on
Commit
82ac1f7
·
1 Parent(s): f855fa4

Try diff-gaussian-rasterizer

Browse files
Files changed (1) hide show
  1. demo/mast3r_demo.py +37 -35
demo/mast3r_demo.py CHANGED
@@ -139,40 +139,40 @@ def get_3D_model_from_scene(scene, scene_state, min_conf_thr=2, as_pointcloud=Fa
139
  return _convert_scene_output_to_glb(outfile, rgbimg, pts3d, msk, focals, cams2world, as_pointcloud=as_pointcloud,
140
  transparent_cams=transparent_cams, cam_size=cam_size, silent=SILENT)
141
 
142
- def save_colmap_scene(scene, save_dir, min_conf_thr=2, clean_depth=False):
143
- if 'save_pointcloud_with_normals' not in globals():
144
- sys.path.append(os.path.join(os.path.dirname(__file__), '../wild-gaussian-splatting/gaussian-splatting'))
145
- sys.path.append(os.path.join(os.path.dirname(__file__), '../wild-gaussian-splatting/src'))
146
- from colmap_dataset_utils import (
147
- inv,
148
- init_filestructure,
149
- save_images_masks,
150
- save_cameras,
151
- save_imagestxt,
152
- save_pointcloud,
153
- save_pointcloud_with_normals
154
- )
155
-
156
- cam2world = scene.get_im_poses().detach().cpu().numpy()
157
- world2cam = inv(cam2world) #
158
- principal_points = scene.get_principal_points().detach().cpu().numpy()
159
- focals = scene.get_focals().detach().cpu().numpy()[..., None]
160
- imgs = np.array(scene.imgs)
161
-
162
- pts3d, _, confs = scene.get_dense_pts3d(clean_depth=clean_depth)
163
- pts3d = [i.detach().reshape(imgs[0].shape) for i in pts3d] #
164
-
165
- masks = to_numpy([c > min_conf_thr for c in to_numpy(confs)])
166
-
167
- # move
168
- mask_images = True
169
-
170
- save_path, images_path, masks_path, sparse_path = init_filestructure(save_dir)
171
- save_images_masks(imgs, masks, images_path, masks_path, mask_images)
172
- save_cameras(focals, principal_points, sparse_path, imgs_shape=imgs.shape)
173
- save_imagestxt(world2cam, sparse_path)
174
- save_pointcloud_with_normals(imgs, pts3d, masks, sparse_path)
175
- return save_path
176
 
177
  @spaces.GPU(duration=10)
178
  def get_reconstructed_scene(image_size, current_scene_state,
@@ -223,7 +223,9 @@ def get_reconstructed_scene(image_size, current_scene_state,
223
  os.makedirs(base_colmapdata_dir, exist_ok=True)
224
  colmap_data_dir = get_next_dir(base_colmapdata_dir)
225
  #
226
- save_colmap_scene(scene, colmap_data_dir, min_conf_thr, clean_depth)
 
 
227
 
228
  if current_scene_state is not None and \
229
  current_scene_state.outfile_name is not None:
 
139
  return _convert_scene_output_to_glb(outfile, rgbimg, pts3d, msk, focals, cams2world, as_pointcloud=as_pointcloud,
140
  transparent_cams=transparent_cams, cam_size=cam_size, silent=SILENT)
141
 
142
+ # def save_colmap_scene(scene, save_dir, min_conf_thr=2, clean_depth=False):
143
+ # if 'save_pointcloud_with_normals' not in globals():
144
+ # sys.path.append(os.path.join(os.path.dirname(__file__), '../wild-gaussian-splatting/gaussian-splatting'))
145
+ # sys.path.append(os.path.join(os.path.dirname(__file__), '../wild-gaussian-splatting/src'))
146
+ # from colmap_dataset_utils import (
147
+ # inv,
148
+ # init_filestructure,
149
+ # save_images_masks,
150
+ # save_cameras,
151
+ # save_imagestxt,
152
+ # save_pointcloud,
153
+ # save_pointcloud_with_normals
154
+ # )
155
+
156
+ # cam2world = scene.get_im_poses().detach().cpu().numpy()
157
+ # world2cam = inv(cam2world) #
158
+ # principal_points = scene.get_principal_points().detach().cpu().numpy()
159
+ # focals = scene.get_focals().detach().cpu().numpy()[..., None]
160
+ # imgs = np.array(scene.imgs)
161
+
162
+ # pts3d, _, confs = scene.get_dense_pts3d(clean_depth=clean_depth)
163
+ # pts3d = [i.detach().reshape(imgs[0].shape) for i in pts3d] #
164
+
165
+ # masks = to_numpy([c > min_conf_thr for c in to_numpy(confs)])
166
+
167
+ # # move
168
+ # mask_images = True
169
+
170
+ # save_path, images_path, masks_path, sparse_path = init_filestructure(save_dir)
171
+ # save_images_masks(imgs, masks, images_path, masks_path, mask_images)
172
+ # save_cameras(focals, principal_points, sparse_path, imgs_shape=imgs.shape)
173
+ # save_imagestxt(world2cam, sparse_path)
174
+ # save_pointcloud_with_normals(imgs, pts3d, masks, sparse_path)
175
+ # return save_path
176
 
177
  @spaces.GPU(duration=10)
178
  def get_reconstructed_scene(image_size, current_scene_state,
 
223
  os.makedirs(base_colmapdata_dir, exist_ok=True)
224
  colmap_data_dir = get_next_dir(base_colmapdata_dir)
225
  #
226
+ # save_colmap_scene(scene, colmap_data_dir, min_conf_thr, clean_depth)
227
+ if 'GaussianRasterizer' not in globals():
228
+ from diff_gaussian_rasterization import GaussianRasterizer, GaussianRasterizationSettings
229
 
230
  if current_scene_state is not None and \
231
  current_scene_state.outfile_name is not None: