Skip to content

Commit a42bb4f

Browse files
committed
files cleaned
1 parent cdb49e4 commit a42bb4f

6 files changed

Lines changed: 52 additions & 44 deletions

File tree

File renamed without changes.
File renamed without changes.
File renamed without changes.

GEMstack/offboard/mast3r_3d_reconstruction/mast3r_runner.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,12 @@
2323
from mast3r.retrieval.processor import Retriever
2424

2525
import mast3r.utils.path_to_dust3r # noqa
26-
from dust3r.dust3r.utils.geometry import inv, geotrf # noqa
27-
from dust3r.dust3r.utils.image import load_images
28-
from dust3r.dust3r.utils.device import to_numpy
29-
from dust3r.dust3r.viz import add_scene_cam, CAM_COLORS, OPENGL, pts3d_to_trimesh, cat_meshes
30-
from dust3r.dust3r.demo import get_args_parser as dust3r_get_args_parser
31-
from dust3r.dust3r.cloud_opt.base_opt import clean_pointcloud
26+
from dust3r.utils.geometry import inv, geotrf # noqa
27+
from dust3r.utils.image import load_images
28+
from dust3r.utils.device import to_numpy
29+
from dust3r.viz import add_scene_cam, CAM_COLORS, OPENGL, pts3d_to_trimesh, cat_meshes
30+
from dust3r.demo import get_args_parser as dust3r_get_args_parser
31+
from dust3r.cloud_opt.base_opt import clean_pointcloud
3232

3333
import matplotlib.pyplot as pl
3434
import open3d as o3d
@@ -314,9 +314,9 @@ def convert_scene_output_to_ply_impl(outfile, imgs, pts3d, mask, scale=1.0, appl
314314
pcd = o3d.geometry.PointCloud()
315315
pcd.points = o3d.utility.Vector3dVector(all_pts)
316316
pcd.colors = o3d.utility.Vector3dVector(all_colors)
317-
317+
print('cwd', os.getcwd())
318318
# Save to .ply
319-
o3d.io.write_point_cloud(outfile, pcd)
319+
o3d.io.write_point_cloud(os.path.join(os.getcwd(), outfile), pcd)
320320
if not silent:
321321
print(f"✅ Exported scaled point cloud to: {outfile}")
322322

GEMstack/offboard/mast3r_3d_reconstruction/scale_pointcloud_based_on_geotag.py

Lines changed: 44 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22
from itertools import combinations
33
from pathlib import Path
44
import 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
77
from pyproj import Transformer
88
import numpy as np
99
from PIL import Image
@@ -23,7 +23,7 @@
2323
import open3d as o3d
2424
from 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
2727
import argparse
2828
from 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

GEMstack/scripts/__init__.py

Whitespace-only changes.

0 commit comments

Comments
 (0)