Skip to content

Commit 9d99981

Browse files
committed
hard code colmap feature to not use gpu
1 parent 40d09c3 commit 9d99981

File tree

1 file changed

+12
-6
lines changed

1 file changed

+12
-6
lines changed

instantsfm/controllers/feature_handler.py

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,33 +19,39 @@ def GenerateDatabase(image_path, database_path, feature_handler_name, config, si
1919
# colmap support from command line. ensure colmap is installed
2020
if feature_handler_name == 'colmap':
2121
import subprocess
22+
# Force COLMAP to run SIFT on CPU to avoid GPU/OpenGL context requirements inside containers
23+
colmap_env = os.environ.copy()
24+
colmap_env["CUDA_VISIBLE_DEVICES"] = ""
2225
feature_extractor_cmd = [
2326
'colmap', 'feature_extractor',
2427
'--image_path', image_path,
2528
'--database_path', database_path,
2629
'--ImageReader.camera_model', 'SIMPLE_RADIAL',
2730
'--ImageReader.single_camera', '1' if single_camera else '0',
28-
'--ImageReader.single_camera_per_folder', '1' if (not single_camera and camera_per_folder) else '0'
31+
'--ImageReader.single_camera_per_folder', '1' if (not single_camera and camera_per_folder) else '0',
32+
'--SiftExtraction.use_gpu', '0'
2933
]
3034
exhaustive_matcher_cmd = [
3135
'colmap', 'exhaustive_matcher',
32-
'--database_path', database_path
36+
'--database_path', database_path,
37+
'--SiftMatching.use_gpu', '0'
3338
]
3439
sequential_matcher_cmd = [
3540
'colmap', 'sequential_matcher',
36-
'--database_path', database_path
41+
'--database_path', database_path,
42+
'--SiftMatching.use_gpu', '0'
3743
]
3844
use_exhaustive = True
3945
matcher_cmd = exhaustive_matcher_cmd if use_exhaustive else sequential_matcher_cmd
4046

4147
try:
4248
print(f"Feature extraction started for {image_path} by {feature_extractor_cmd}")
43-
subprocess.run(feature_extractor_cmd, check=True)
49+
subprocess.run(feature_extractor_cmd, check=True, env=colmap_env)
4450
print(f"Feature extraction completed for {image_path}")
4551
except subprocess.CalledProcessError as e:
4652
print(f"Error during feature extraction: {e}")
4753
try:
48-
subprocess.run(matcher_cmd, check=True)
54+
subprocess.run(matcher_cmd, check=True, env=colmap_env)
4955
print(f"Exhaustive matching completed for {database_path}")
5056
except subprocess.CalledProcessError as e:
5157
print(f"Error during exhaustive matching: {e}")
@@ -352,4 +358,4 @@ def match_handling(pair_id, match):
352358
print(f"Two view geometries added to database in {time.time() - start_time} seconds")
353359

354360
db.add_feature_name(feature_handler_name)
355-
db.commit()
361+
db.commit()

0 commit comments

Comments
 (0)