MCPcopy
hub / github.com/naver/dust3r / get_reconstructed_scene

Function get_reconstructed_scene

dust3r/demo.py:135–186  ·  view source on GitHub ↗

from a list of images, run dust3r inference, global aligner. then run get_3D_model_from_scene

(outdir, model, device, silent, image_size, filelist, schedule, niter, min_conf_thr,
                            as_pointcloud, mask_sky, clean_depth, transparent_cams, cam_size,
                            scenegraph_type, winsize, refid)

Source from the content-addressed store, hash-verified

133
134
135def get_reconstructed_scene(outdir, model, device, silent, image_size, filelist, schedule, niter, min_conf_thr,
136 as_pointcloud, mask_sky, clean_depth, transparent_cams, cam_size,
137 scenegraph_type, winsize, refid):
138 """
139 from a list of images, run dust3r inference, global aligner.
140 then run get_3D_model_from_scene
141 """
142 try:
143 square_ok = model.square_ok
144 except Exception as e:
145 square_ok = False
146 imgs = load_images(filelist, size=image_size, verbose=not silent, patch_size=model.patch_size, square_ok=square_ok)
147 if len(imgs) == 1:
148 imgs = [imgs[0], copy.deepcopy(imgs[0])]
149 imgs[1]['idx'] = 1
150 if scenegraph_type == "swin":
151 scenegraph_type = scenegraph_type + "-" + str(winsize)
152 elif scenegraph_type == "oneref":
153 scenegraph_type = scenegraph_type + "-" + str(refid)
154
155 pairs = make_pairs(imgs, scene_graph=scenegraph_type, prefilter=None, symmetrize=True)
156 output = inference(pairs, model, device, batch_size=1, verbose=not silent)
157
158 mode = GlobalAlignerMode.PointCloudOptimizer if len(imgs) > 2 else GlobalAlignerMode.PairViewer
159 scene = global_aligner(output, device=device, mode=mode, verbose=not silent)
160 lr = 0.01
161
162 if mode == GlobalAlignerMode.PointCloudOptimizer:
163 loss = scene.compute_global_alignment(init='mst', niter=niter, schedule=schedule, lr=lr)
164
165 outfile = get_3D_model_from_scene(outdir, silent, scene, min_conf_thr, as_pointcloud, mask_sky,
166 clean_depth, transparent_cams, cam_size)
167
168 # also return rgb, depth and confidence imgs
169 # depth is normalized with the max value for all images
170 # we apply the jet colormap on the confidence maps
171 rgbimg = scene.imgs
172 depths = to_numpy(scene.get_depthmaps())
173 confs = to_numpy([c for c in scene.im_conf])
174 cmap = pl.get_cmap('jet')
175 depths_max = max([d.max() for d in depths])
176 depths = [d / depths_max for d in depths]
177 confs_max = max([d.max() for d in confs])
178 confs = [cmap(d / confs_max) for d in confs]
179
180 imgs = []
181 for i in range(len(rgbimg)):
182 imgs.append(rgbimg[i])
183 imgs.append(rgb(depths[i]))
184 imgs.append(rgb(confs[i]))
185
186 return scene, outfile, imgs
187
188
189def set_scenegraph_options(inputfiles, winsize, refid, scenegraph_type):

Callers

nothing calls this directly

Calls 9

load_imagesFunction · 0.90
make_pairsFunction · 0.90
inferenceFunction · 0.90
global_alignerFunction · 0.90
to_numpyFunction · 0.90
rgbFunction · 0.90
get_3D_model_from_sceneFunction · 0.85
get_depthmapsMethod · 0.45

Tested by

no test coverage detected