abreza commited on
Commit
ab79a8a
·
1 Parent(s): 6045388

Improve bundle adjustment configuration by ensuring constant camera pose is set only for valid registered images.

Browse files
models/SpaTrackV2/models/tracker3D/spatrack_modules/ba.py CHANGED
@@ -502,13 +502,27 @@ def ba_pycolmap(world_tracks, intrs, c2w_traj, visb, tracks2d, image_size, cam_t
502
  ba_options.refine_extra_params = False
503
  ba_config = pycolmap.BundleAdjustmentConfig()
504
  reg_image_ids = rec.reg_image_ids()
505
- for image_id in reg_image_ids:
506
- ba_config.add_image(image_id)
507
  # Fix frame 0 (or the first available frame), i.e, the end frame of the last window
508
  if len(reg_image_ids) == 0:
509
  return c2w_traj_glob, world_tracks_refine, intrs
510
- first_image_id = min(reg_image_ids) if 0 not in reg_image_ids else 0
511
- ba_config.set_constant_cam_pose(first_image_id)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
512
 
513
  # fix the 3d points
514
  for point3D_id in rec.points3D:
 
502
  ba_options.refine_extra_params = False
503
  ba_config = pycolmap.BundleAdjustmentConfig()
504
  reg_image_ids = rec.reg_image_ids()
505
+
 
506
  # Fix frame 0 (or the first available frame), i.e, the end frame of the last window
507
  if len(reg_image_ids) == 0:
508
  return c2w_traj_glob, world_tracks_refine, intrs
509
+
510
+ # Add all registered images to bundle adjustment config
511
+ for image_id in reg_image_ids:
512
+ ba_config.add_image(image_id)
513
+
514
+ # Select the first image to fix - prefer 0 if available, otherwise use the minimum available id
515
+ first_image_id = 0 if 0 in reg_image_ids else min(reg_image_ids)
516
+
517
+ # Only set constant pose if the image was successfully added
518
+ if ba_config.has_image(first_image_id):
519
+ ba_config.set_constant_cam_pose(first_image_id)
520
+ elif len(reg_image_ids) > 0:
521
+ # Fallback: try with the first registered image
522
+ for img_id in sorted(reg_image_ids):
523
+ if ba_config.has_image(img_id):
524
+ ba_config.set_constant_cam_pose(img_id)
525
+ break
526
 
527
  # fix the 3d points
528
  for point3D_id in rec.points3D: