This repository has no description
1@echo off
2setlocal
3
4REM --- Windows Batch Version of inky/colmap.sh ---
5REM --- Modified to use CUDA for GPU acceleration ---
6
7REM Prerequisites:
8REM 1. ffmpeg.exe and colmap.exe must be in the system PATH or the same directory as this script.
9REM 2. The COLMAP build MUST support CUDA.
10REM 3. Appropriate NVIDIA drivers and CUDA toolkit (compatible with your COLMAP build) must be installed.
11
12REM Define paths (using backslashes for Windows compatibility)
13set INPUT_VIDEO=data\input.mov
14set FRAMES_DIR=data\frames
15set COLMAP_DB=data\colmap.db
16set SPARSE_DIR=data\sparse
17set DENSE_DIR=data\dense
18
19REM Check if input video exists
20if not exist "%INPUT_VIDEO%" (
21 echo Error: Input video not found at %INPUT_VIDEO%
22 exit /b 1
23)
24
25REM Create directories
26echo Creating directories...
27if not exist "data" mkdir "data"
28if not exist "%FRAMES_DIR%" mkdir "%FRAMES_DIR%"
29if errorlevel 1 ( echo Failed to create %FRAMES_DIR%. & exit /b 1 )
30if not exist "%SPARSE_DIR%" mkdir "%SPARSE_DIR%"
31if errorlevel 1 ( echo Failed to create %SPARSE_DIR%. & exit /b 1 )
32if not exist "%DENSE_DIR%" mkdir "%DENSE_DIR%"
33if errorlevel 1 ( echo Failed to create %DENSE_DIR%. & exit /b 1 )
34
35REM Step 1: Extract frames from video
36echo Extracting frames from video...
37ffmpeg -i "%INPUT_VIDEO%" -q:v 1 "%FRAMES_DIR%\frame_%%04d.jpg"
38if errorlevel 1 (
39 echo Error: ffmpeg frame extraction failed. Check ffmpeg output/log.
40 exit /b 1
41)
42
43REM Step 2: Run COLMAP feature extraction (Using CUDA GPU)
44echo Running COLMAP feature extraction (CUDA)...
45colmap feature_extractor ^
46 --database_path "%COLMAP_DB%" ^
47 --image_path "%FRAMES_DIR%" ^
48 --ImageReader.camera_model SIMPLE_RADIAL ^
49 --SiftExtraction.use_gpu 1
50if errorlevel 1 (
51 echo Error: COLMAP feature_extractor failed. Check COLMAP output/log. Ensure CUDA is working.
52 exit /b 1
53)
54
55REM Step 3: Run COLMAP feature matching (Using CUDA GPU)
56echo Running COLMAP feature matching (CUDA)...
57colmap exhaustive_matcher ^
58 --database_path "%COLMAP_DB%" ^
59 --SiftMatching.use_gpu 1
60if errorlevel 1 (
61 echo Error: COLMAP exhaustive_matcher failed. Check COLMAP output/log. Ensure CUDA is working.
62 exit /b 1
63)
64
65REM Step 4: Run COLMAP sparse reconstruction
66REM Note: The 'mapper' step primarily uses CPU.
67echo Running COLMAP sparse reconstruction...
68colmap mapper ^
69 --database_path "%COLMAP_DB%" ^
70 --image_path "%FRAMES_DIR%" ^
71 --output_path "%SPARSE_DIR%"
72if errorlevel 1 (
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.
76)
77
78REM Check if the expected output directory from mapper exists
79REM COLMAP often creates numbered subdirectories (0, 1, ...) for different models.
80REM We assume the first model (0) is the one we want.
81if 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.
84 exit /b 1
85)
86
87REM Step 5: Run COLMAP dense reconstruction
88echo Running COLMAP image undistorter...
89colmap image_undistorter ^
90 --image_path "%FRAMES_DIR%" ^
91 --input_path "%SPARSE_DIR%\0" ^
92 --output_path "%DENSE_DIR%"
93if errorlevel 1 (
94 echo Error: COLMAP image_undistorter failed. Check COLMAP output/log.
95 exit /b 1
96)
97
98echo Running COLMAP patch matching (Using CUDA GPU)...
99REM Use --PatchMatchStereo.gpu_index 0 to select the first CUDA device. Change if needed.
100colmap patch_match_stereo ^
101 --workspace_path "%DENSE_DIR%" ^
102 --PatchMatchStereo.gpu_index 0
103if errorlevel 1 (
104 echo Error: COLMAP patch_match_stereo failed. Check COLMAP output/log. Ensure CUDA is working.
105 exit /b 1
106)
107
108echo Running COLMAP stereo fusion...
109REM Note: Stereo fusion is primarily CPU-bound.
110colmap stereo_fusion ^
111 --workspace_path "%DENSE_DIR%" ^
112 --output_path "%DENSE_DIR%\fused.ply"
113if errorlevel 1 (
114 echo Error: COLMAP stereo_fusion failed. Check COLMAP output/log.
115 exit /b 1
116)
117
118REM Output camera pose information
119echo Extracting camera pose information...
120colmap model_converter ^
121 --input_path "%SPARSE_DIR%\0" ^
122 --output_path "%SPARSE_DIR%\txt" ^
123 --output_type TXT
124if errorlevel 1 (
125 echo Error: COLMAP model_converter failed. Check COLMAP output/log.
126 exit /b 1
127)
128
129echo COLMAP processing complete!
130echo Camera poses are in: %SPARSE_DIR%\txt\images.txt
131echo Dense point cloud is in: %DENSE_DIR%\fused.ply
132
133echo Script completed successfully
134endlocal
135exit /b 0