···
4
+
REM --- Windows Batch Version of inky/colmap.sh ---
5
+
REM --- Modified to use CUDA for GPU acceleration ---
8
+
REM 1. ffmpeg.exe and colmap.exe must be in the system PATH or the same directory as this script.
9
+
REM 2. The COLMAP build MUST support CUDA.
10
+
REM 3. Appropriate NVIDIA drivers and CUDA toolkit (compatible with your COLMAP build) must be installed.
12
+
REM Define paths (using backslashes for Windows compatibility)
13
+
set INPUT_VIDEO=data\input.mov
14
+
set FRAMES_DIR=data\frames
15
+
set COLMAP_DB=data\colmap.db
16
+
set SPARSE_DIR=data\sparse
17
+
set DENSE_DIR=data\dense
19
+
REM Check if input video exists
20
+
if not exist "%INPUT_VIDEO%" (
21
+
echo Error: Input video not found at %INPUT_VIDEO%
25
+
REM Create directories
26
+
echo Creating directories...
27
+
if not exist "data" mkdir "data"
28
+
if not exist "%FRAMES_DIR%" mkdir "%FRAMES_DIR%"
29
+
if errorlevel 1 ( echo Failed to create %FRAMES_DIR%. & exit /b 1 )
30
+
if not exist "%SPARSE_DIR%" mkdir "%SPARSE_DIR%"
31
+
if errorlevel 1 ( echo Failed to create %SPARSE_DIR%. & exit /b 1 )
32
+
if not exist "%DENSE_DIR%" mkdir "%DENSE_DIR%"
33
+
if errorlevel 1 ( echo Failed to create %DENSE_DIR%. & exit /b 1 )
35
+
REM Step 1: Extract frames from video
36
+
echo Extracting frames from video...
37
+
ffmpeg -i "%INPUT_VIDEO%" -q:v 1 "%FRAMES_DIR%\frame_%%04d.jpg"
39
+
echo Error: ffmpeg frame extraction failed. Check ffmpeg output/log.
43
+
REM Step 2: Run COLMAP feature extraction (Using CUDA GPU)
44
+
echo Running COLMAP feature extraction (CUDA)...
45
+
colmap feature_extractor ^
46
+
--database_path "%COLMAP_DB%" ^
47
+
--image_path "%FRAMES_DIR%" ^
48
+
--ImageReader.camera_model SIMPLE_RADIAL ^
49
+
--SiftExtraction.use_gpu 1
51
+
echo Error: COLMAP feature_extractor failed. Check COLMAP output/log. Ensure CUDA is working.
55
+
REM Step 3: Run COLMAP feature matching (Using CUDA GPU)
56
+
echo Running COLMAP feature matching (CUDA)...
57
+
colmap exhaustive_matcher ^
58
+
--database_path "%COLMAP_DB%" ^
59
+
--SiftMatching.use_gpu 1
61
+
echo Error: COLMAP exhaustive_matcher failed. Check COLMAP output/log. Ensure CUDA is working.
65
+
REM Step 4: Run COLMAP sparse reconstruction
66
+
REM Note: The 'mapper' step primarily uses CPU.
67
+
echo Running COLMAP sparse reconstruction...
69
+
--database_path "%COLMAP_DB%" ^
70
+
--image_path "%FRAMES_DIR%" ^
71
+
--output_path "%SPARSE_DIR%"
73
+
echo Warning: COLMAP mapper returned an error code (%ERRORLEVEL%), but proceeding. Check COLMAP output/log.
74
+
REM Mapper might "fail" (e.g., if few matches) but sometimes produces usable results.
75
+
REM More robust checking might be needed depending on COLMAP's specific exit codes.
78
+
REM Check if the expected output directory from mapper exists
79
+
REM COLMAP often creates numbered subdirectories (0, 1, ...) for different models.
80
+
REM We assume the first model (0) is the one we want.
81
+
if not exist "%SPARSE_DIR%\0" (
82
+
echo Error: Sparse reconstruction output directory (%SPARSE_DIR%\0) not found.
83
+
echo Mapper likely failed to produce a valid reconstruction. Check COLMAP output/log.
87
+
REM Step 5: Run COLMAP dense reconstruction
88
+
echo Running COLMAP image undistorter...
89
+
colmap image_undistorter ^
90
+
--image_path "%FRAMES_DIR%" ^
91
+
--input_path "%SPARSE_DIR%\0" ^
92
+
--output_path "%DENSE_DIR%"
94
+
echo Error: COLMAP image_undistorter failed. Check COLMAP output/log.
98
+
echo Running COLMAP patch matching (Using CUDA GPU)...
99
+
REM Use --PatchMatchStereo.gpu_index 0 to select the first CUDA device. Change if needed.
100
+
colmap patch_match_stereo ^
101
+
--workspace_path "%DENSE_DIR%" ^
102
+
--PatchMatchStereo.gpu_index 0
104
+
echo Error: COLMAP patch_match_stereo failed. Check COLMAP output/log. Ensure CUDA is working.
108
+
echo Running COLMAP stereo fusion...
109
+
REM Note: Stereo fusion is primarily CPU-bound.
110
+
colmap stereo_fusion ^
111
+
--workspace_path "%DENSE_DIR%" ^
112
+
--output_path "%DENSE_DIR%\fused.ply"
114
+
echo Error: COLMAP stereo_fusion failed. Check COLMAP output/log.
118
+
REM Output camera pose information
119
+
echo Extracting camera pose information...
120
+
colmap model_converter ^
121
+
--input_path "%SPARSE_DIR%\0" ^
122
+
--output_path "%SPARSE_DIR%\txt" ^
125
+
echo Error: COLMAP model_converter failed. Check COLMAP output/log.
129
+
echo COLMAP processing complete!
130
+
echo Camera poses are in: %SPARSE_DIR%\txt\images.txt
131
+
echo Dense point cloud is in: %DENSE_DIR%\fused.ply
133
+
echo Script completed successfully