22from itertools import combinations
33from pathlib import Path
44import numpy as np
5- from mast3r .mast3r . model import AsymmetricMASt3R
6- from mast3r .mast3r . utils .misc import hash_md5
5+ from mast3r .model import AsymmetricMASt3R
6+ from mast3r .utils .misc import hash_md5
77from pyproj import Transformer
88import numpy as np
99from PIL import Image
2323import open3d as o3d
2424from scipy .spatial .transform import Rotation
2525
26- from mast3r .mast3r . demo import get_args_parser , main_demo
26+ from mast3r .demo import get_args_parser , main_demo
2727import argparse
2828from mast3r_runner import get_reconstructed_scene , convert_scene_output_to_ply
2929
@@ -238,34 +238,35 @@ def get_context(tmp_dir):
238238 args .scenegraph_type , args .winsize , args .win_cyclic , args .refid , 0 , args .shared_intrinsics )
239239 return scene_state , outfile
240240
241- def add_parse_args (parser ):
242- parser .add_argument ('--folder_path' , type = str , required = True )
243- parser .add_argument ('--output_path' , type = str , required = True )
244- parser .add_argument ('--scale_method' , type = str , required = True )
245-
246- parser .add_argument ('--weights_path' , type = str , required = True , help = 'Path to the core mast3rweights file' )
247- parser .add_argument ('--retrieval_model' , type = str , required = True , help = 'Retrieval model weights path that is used to make image pairs' )
248- parser .add_argument ('--device' , type = str , required = True , help = 'Device to run the model on' )
249- parser .add_argument ('--silent' , type = bool , required = True , help = 'Whether to run the model silently' )
250- parser .add_argument ('--image_size' , type = int , required = True , help = 'Image size' )
251- parser .add_argument ('--optim_level' , type = int , required = True , help = 'Optimization level' )
252- parser .add_argument ('--lr1' , type = float , required = True , help = 'Learning rate for the first refinement iteration stage' )
253- parser .add_argument ('--niter1' , type = int , required = True , help = 'Number of iterations for the first refinement iteration stage' )
254- parser .add_argument ('--lr2' , type = float , required = True , help = 'Learning rate for the second refinement iteration stage' )
255- parser .add_argument ('--niter2' , type = int , required = True , help = 'Number of iterations for the second refinement iteration stage' )
256- parser .add_argument ('--min_conf_thr' , type = float , required = True , help = 'Minimum confidence threshold' )
257- parser .add_argument ('--matching_conf_thr' , type = float , required = True , help = 'Matching confidence threshold' )
258- # parser.add_argument('--as_pointcloud', type=bool, required=True, help='Whether to output a pointcloud')
259- # parser.add_argument('--mask_sky', type=bool, required=True, help='Whether to mask the sky')
260- parser .add_argument ('--clean_depth' , type = bool , required = True , help = 'Whether to clean the depth' )
261- parser .add_argument ('--transparent_cams' , type = bool , required = True , help = 'Whether to make the cameras transparent' )
262- parser .add_argument ('--cam_size' , type = float , required = True , help = 'Camera size' )
263- parser .add_argument ('--scenegraph_type' , type = str , required = True , help = 'Scenegraph type' )
264- parser .add_argument ('--winsize' , type = int , required = True , help = 'Window size for sliding window pair making scenegraph_type' )
265- parser .add_argument ('--win_cyclic' , type = bool , required = True , help = 'Whether to use a cyclic sliding window' )
266- parser .add_argument ('--refid' , type = str , required = True , help = 'Reference image for retrieval' )
267- # parser.add_argument('--TSDF_thresh', type=float, required=True, help='TSDF refinement threshold')
268- parser .add_argument ('--shared_intrinsics' , type = bool , required = True , help = 'Whether to use a shared intrinsics model' )
241+ def add_parse_args (parser , is_scene_path = False ):
242+ parser .add_argument ('--folder_path' , type = str , required = True , help = 'Path to the folder containing the images' )
243+ parser .add_argument ('--output_path' , type = str , required = True , help = 'Path to the output file' )
244+ parser .add_argument ('--scale_method' , type = str , required = True , help = 'Method to use for scale estimation' )
245+ parser .add_argument ('--scene_path' , type = str , required = False , help = 'Path to the scene file' )
246+ if not is_scene_path :
247+ parser .add_argument ('--weights_path' , type = str , required = True , help = 'Path to the core mast3rweights file' )
248+ # parser.add_argument('--retrieval_model', type=str, required=True, help='Retrieval model weights path that is used to make image pairs')
249+ # parser.add_argument('--device', type=str, required=True, help='Device to run the model on')
250+ # parser.add_argument('--silent', type=bool, required=True, help='Whether to run the model silently')
251+ # parser.add_argument('--image_size', type=int, required=True, help='Image size')
252+ parser .add_argument ('--optim_level' , type = int , required = True , help = 'Optimization level' )
253+ parser .add_argument ('--lr1' , type = float , required = True , help = 'Learning rate for the first refinement iteration stage' )
254+ parser .add_argument ('--niter1' , type = int , required = True , help = 'Number of iterations for the first refinement iteration stage' )
255+ parser .add_argument ('--lr2' , type = float , required = True , help = 'Learning rate for the second refinement iteration stage' )
256+ parser .add_argument ('--niter2' , type = int , required = True , help = 'Number of iterations for the second refinement iteration stage' )
257+ parser .add_argument ('--min_conf_thr' , type = float , required = True , help = 'Minimum confidence threshold' )
258+ parser .add_argument ('--matching_conf_thr' , type = float , required = True , help = 'Matching confidence threshold' )
259+ # parser.add_argument('--as_pointcloud', type=bool, required=True, help='Whether to output a pointcloud')
260+ # parser.add_argument('--mask_sky', type=bool, required=True, help='Whether to mask the sky')
261+ parser .add_argument ('--clean_depth' , type = bool , required = True , help = 'Whether to clean the depth' )
262+ parser .add_argument ('--transparent_cams' , type = bool , required = True , help = 'Whether to make the cameras transparent' )
263+ parser .add_argument ('--cam_size' , type = float , required = True , help = 'Camera size' )
264+ parser .add_argument ('--scenegraph_type' , type = str , required = True , help = 'Scenegraph type' )
265+ parser .add_argument ('--winsize' , type = int , required = True , help = 'Window size for sliding window pair making scenegraph_type' )
266+ parser .add_argument ('--win_cyclic' , type = bool , required = True , help = 'Whether to use a cyclic sliding window' )
267+ parser .add_argument ('--refid' , type = str , required = True , help = 'Reference image for retrieval' )
268+ # parser.add_argument('--TSDF_thresh', type=float, required=True, help='TSDF refinement threshold')
269+ parser .add_argument ('--shared_intrinsics' , type = bool , required = True , help = 'Whether to use a shared intrinsics model' )
269270
270271
271272 return parser
@@ -281,16 +282,16 @@ def scale_pointcloud_based_on_geotag():
281282
282283 if not args .scene_path :
283284 args_parser = get_args_parser ()
284- args_parser = add_parse_args (args_parser )
285+ args_parser = add_parse_args (args_parser , is_scene_path = False )
285286 args = args_parser .parse_args ()
286287 scene , outfile = run_mast3r (args )
287288 scene .get_dense_pts3d ()
288289 data = scene
289290 else :
290291 args_parser = argparse .ArgumentParser ()
291- args_parser = add_parse_args (args_parser )
292+ args_parser = add_parse_args (args_parser , is_scene_path = True )
292293 args = args_parser .parse_args ()
293-
294+ print ( 'cwd' , os . getcwd ())
294295 with open (args .scene_path , 'rb' ) as f :
295296 data = pickle .load (f )
296297
@@ -305,11 +306,18 @@ def scale_pointcloud_based_on_geotag():
305306 }
306307 image_names = extract_image_names (data .img_paths )
307308 xyz_lookup = gps_to_xyz (gps_lookup )
309+ scale = 1.0
308310 for method in ['ransac' , 'median' ]:
309311 if method == 'ransac' :
310- scale , sfm_dists , gps_dists = estimate_scale_ransac (camera_centers , xyz_lookup , image_names )
312+ # print('camera_centers', camera_centers, )
313+ # print('xyz_lookup', xyz_lookup)
314+ # print('image_names', image_names)
315+ scale , sfm_dists , gps_dists = estimate_scale_ransac (camera_centers .cpu ().numpy (), xyz_lookup , image_names )
316+ print ('scale' , scale )
317+ print ('sfm_dists' , sfm_dists )
318+ print ('gps_dists' , gps_dists )
311319 else :
312- scale , sfm_dists , gps_dists = estimate_3d_scale_from_gps (camera_centers , xyz_lookup , image_names )
320+ scale , sfm_dists , gps_dists = estimate_3d_scale_from_gps (camera_centers . cpu (). numpy () , xyz_lookup , image_names )
313321 print (f"Estimated scale: { scale } " )
314322 convert_scene_output_to_ply (args .output_path , data , scale = scale , apply_y_flip = False )
315323
0 commit comments