tangled
alpha
login
or
join now
dunkirk.sh
/
inky
1
fork
atom
an eink camera running on an rpi zero 2 w
1
fork
atom
overview
issues
pulls
pipelines
feat: add colmap scripts
dunkirk.sh
10 months ago
51e6bef8
9b7daf6e
verified
This commit was signed with the committer's
known signature
.
dunkirk.sh
SSH Key Fingerprint:
SHA256:DqcG0RXYExE26KiWo3VxJnsxswN1QNfTBvB+bdSpk80=
+205
3 changed files
expand all
collapse all
unified
split
.gitignore
colmap.bat
colmap.sh
+2
.gitignore
···
1
1
+
data/
2
2
+
PROSPECTUS.md
+135
colmap.bat
···
1
1
+
@echo off
2
2
+
setlocal
3
3
+
4
4
+
REM --- Windows Batch Version of inky/colmap.sh ---
5
5
+
REM --- Modified to use CUDA for GPU acceleration ---
6
6
+
7
7
+
REM Prerequisites:
8
8
+
REM 1. ffmpeg.exe and colmap.exe must be in the system PATH or the same directory as this script.
9
9
+
REM 2. The COLMAP build MUST support CUDA.
10
10
+
REM 3. Appropriate NVIDIA drivers and CUDA toolkit (compatible with your COLMAP build) must be installed.
11
11
+
12
12
+
REM Define paths (using backslashes for Windows compatibility)
13
13
+
set INPUT_VIDEO=data\input.mov
14
14
+
set FRAMES_DIR=data\frames
15
15
+
set COLMAP_DB=data\colmap.db
16
16
+
set SPARSE_DIR=data\sparse
17
17
+
set DENSE_DIR=data\dense
18
18
+
19
19
+
REM Check if input video exists
20
20
+
if not exist "%INPUT_VIDEO%" (
21
21
+
echo Error: Input video not found at %INPUT_VIDEO%
22
22
+
exit /b 1
23
23
+
)
24
24
+
25
25
+
REM Create directories
26
26
+
echo Creating directories...
27
27
+
if not exist "data" mkdir "data"
28
28
+
if not exist "%FRAMES_DIR%" mkdir "%FRAMES_DIR%"
29
29
+
if errorlevel 1 ( echo Failed to create %FRAMES_DIR%. & exit /b 1 )
30
30
+
if not exist "%SPARSE_DIR%" mkdir "%SPARSE_DIR%"
31
31
+
if errorlevel 1 ( echo Failed to create %SPARSE_DIR%. & exit /b 1 )
32
32
+
if not exist "%DENSE_DIR%" mkdir "%DENSE_DIR%"
33
33
+
if errorlevel 1 ( echo Failed to create %DENSE_DIR%. & exit /b 1 )
34
34
+
35
35
+
REM Step 1: Extract frames from video
36
36
+
echo Extracting frames from video...
37
37
+
ffmpeg -i "%INPUT_VIDEO%" -q:v 1 "%FRAMES_DIR%\frame_%%04d.jpg"
38
38
+
if errorlevel 1 (
39
39
+
echo Error: ffmpeg frame extraction failed. Check ffmpeg output/log.
40
40
+
exit /b 1
41
41
+
)
42
42
+
43
43
+
REM Step 2: Run COLMAP feature extraction (Using CUDA GPU)
44
44
+
echo Running COLMAP feature extraction (CUDA)...
45
45
+
colmap feature_extractor ^
46
46
+
--database_path "%COLMAP_DB%" ^
47
47
+
--image_path "%FRAMES_DIR%" ^
48
48
+
--ImageReader.camera_model SIMPLE_RADIAL ^
49
49
+
--SiftExtraction.use_gpu 1
50
50
+
if errorlevel 1 (
51
51
+
echo Error: COLMAP feature_extractor failed. Check COLMAP output/log. Ensure CUDA is working.
52
52
+
exit /b 1
53
53
+
)
54
54
+
55
55
+
REM Step 3: Run COLMAP feature matching (Using CUDA GPU)
56
56
+
echo Running COLMAP feature matching (CUDA)...
57
57
+
colmap exhaustive_matcher ^
58
58
+
--database_path "%COLMAP_DB%" ^
59
59
+
--SiftMatching.use_gpu 1
60
60
+
if errorlevel 1 (
61
61
+
echo Error: COLMAP exhaustive_matcher failed. Check COLMAP output/log. Ensure CUDA is working.
62
62
+
exit /b 1
63
63
+
)
64
64
+
65
65
+
REM Step 4: Run COLMAP sparse reconstruction
66
66
+
REM Note: The 'mapper' step primarily uses CPU.
67
67
+
echo Running COLMAP sparse reconstruction...
68
68
+
colmap mapper ^
69
69
+
--database_path "%COLMAP_DB%" ^
70
70
+
--image_path "%FRAMES_DIR%" ^
71
71
+
--output_path "%SPARSE_DIR%"
72
72
+
if errorlevel 1 (
73
73
+
echo Warning: COLMAP mapper returned an error code (%ERRORLEVEL%), but proceeding. Check COLMAP output/log.
74
74
+
REM Mapper might "fail" (e.g., if few matches) but sometimes produces usable results.
75
75
+
REM More robust checking might be needed depending on COLMAP's specific exit codes.
76
76
+
)
77
77
+
78
78
+
REM Check if the expected output directory from mapper exists
79
79
+
REM COLMAP often creates numbered subdirectories (0, 1, ...) for different models.
80
80
+
REM We assume the first model (0) is the one we want.
81
81
+
if not exist "%SPARSE_DIR%\0" (
82
82
+
echo Error: Sparse reconstruction output directory (%SPARSE_DIR%\0) not found.
83
83
+
echo Mapper likely failed to produce a valid reconstruction. Check COLMAP output/log.
84
84
+
exit /b 1
85
85
+
)
86
86
+
87
87
+
REM Step 5: Run COLMAP dense reconstruction
88
88
+
echo Running COLMAP image undistorter...
89
89
+
colmap image_undistorter ^
90
90
+
--image_path "%FRAMES_DIR%" ^
91
91
+
--input_path "%SPARSE_DIR%\0" ^
92
92
+
--output_path "%DENSE_DIR%"
93
93
+
if errorlevel 1 (
94
94
+
echo Error: COLMAP image_undistorter failed. Check COLMAP output/log.
95
95
+
exit /b 1
96
96
+
)
97
97
+
98
98
+
echo Running COLMAP patch matching (Using CUDA GPU)...
99
99
+
REM Use --PatchMatchStereo.gpu_index 0 to select the first CUDA device. Change if needed.
100
100
+
colmap patch_match_stereo ^
101
101
+
--workspace_path "%DENSE_DIR%" ^
102
102
+
--PatchMatchStereo.gpu_index 0
103
103
+
if errorlevel 1 (
104
104
+
echo Error: COLMAP patch_match_stereo failed. Check COLMAP output/log. Ensure CUDA is working.
105
105
+
exit /b 1
106
106
+
)
107
107
+
108
108
+
echo Running COLMAP stereo fusion...
109
109
+
REM Note: Stereo fusion is primarily CPU-bound.
110
110
+
colmap stereo_fusion ^
111
111
+
--workspace_path "%DENSE_DIR%" ^
112
112
+
--output_path "%DENSE_DIR%\fused.ply"
113
113
+
if errorlevel 1 (
114
114
+
echo Error: COLMAP stereo_fusion failed. Check COLMAP output/log.
115
115
+
exit /b 1
116
116
+
)
117
117
+
118
118
+
REM Output camera pose information
119
119
+
echo Extracting camera pose information...
120
120
+
colmap model_converter ^
121
121
+
--input_path "%SPARSE_DIR%\0" ^
122
122
+
--output_path "%SPARSE_DIR%\txt" ^
123
123
+
--output_type TXT
124
124
+
if errorlevel 1 (
125
125
+
echo Error: COLMAP model_converter failed. Check COLMAP output/log.
126
126
+
exit /b 1
127
127
+
)
128
128
+
129
129
+
echo COLMAP processing complete!
130
130
+
echo Camera poses are in: %SPARSE_DIR%\txt\images.txt
131
131
+
echo Dense point cloud is in: %DENSE_DIR%\fused.ply
132
132
+
133
133
+
echo Script completed successfully
134
134
+
endlocal
135
135
+
exit /b 0
+68
colmap.sh
···
1
1
+
#!/usr/bin/env -S nix shell --impure nixpkgs#ffmpeg nixpkgs#colmap nixpkgs#opencv4 --command bash
2
2
+
3
3
+
set -euo pipefail
4
4
+
5
5
+
# Define paths
6
6
+
INPUT_VIDEO="data/input.mov"
7
7
+
FRAMES_DIR="data/frames"
8
8
+
COLMAP_DB="data/colmap.db"
9
9
+
SPARSE_DIR="data/sparse"
10
10
+
DENSE_DIR="data/dense"
11
11
+
12
12
+
# Create directories
13
13
+
mkdir -p "$FRAMES_DIR" "$SPARSE_DIR" "$DENSE_DIR"
14
14
+
15
15
+
# Step 1: Extract frames from video
16
16
+
echo "Extracting frames from video..."
17
17
+
ffmpeg -i "$INPUT_VIDEO" -q:v 1 "$FRAMES_DIR/frame_%04d.jpg"
18
18
+
19
19
+
# Step 2: Run COLMAP feature extraction (CPU only)
20
20
+
echo "Running COLMAP feature extraction..."
21
21
+
colmap feature_extractor \
22
22
+
--database_path "$COLMAP_DB" \
23
23
+
--image_path "$FRAMES_DIR" \
24
24
+
--ImageReader.camera_model SIMPLE_RADIAL \
25
25
+
--SiftExtraction.use_gpu 0
26
26
+
27
27
+
# Step 3: Run COLMAP feature matching (CPU only)
28
28
+
echo "Running COLMAP feature matching..."
29
29
+
colmap exhaustive_matcher \
30
30
+
--database_path "$COLMAP_DB" \
31
31
+
--SiftMatching.use_gpu 0
32
32
+
33
33
+
# Step 4: Run COLMAP sparse reconstruction
34
34
+
echo "Running COLMAP sparse reconstruction..."
35
35
+
colmap mapper \
36
36
+
--database_path "$COLMAP_DB" \
37
37
+
--image_path "$FRAMES_DIR" \
38
38
+
--output_path "$SPARSE_DIR"
39
39
+
40
40
+
# Step 5: Run COLMAP dense reconstruction
41
41
+
echo "Running COLMAP image undistorter..."
42
42
+
colmap image_undistorter \
43
43
+
--image_path "$FRAMES_DIR" \
44
44
+
--input_path "$SPARSE_DIR/0" \
45
45
+
--output_path "$DENSE_DIR"
46
46
+
47
47
+
echo "Running COLMAP patch matching (CPU only)..."
48
48
+
colmap patch_match_stereo \
49
49
+
--workspace_path "$DENSE_DIR" \
50
50
+
--PatchMatchStereo.gpu_index -1
51
51
+
52
52
+
echo "Running COLMAP stereo fusion..."
53
53
+
colmap stereo_fusion \
54
54
+
--workspace_path "$DENSE_DIR" \
55
55
+
--output_path "$DENSE_DIR/fused.ply"
56
56
+
57
57
+
# Output camera pose information for dithering
58
58
+
echo "Extracting camera pose information..."
59
59
+
colmap model_converter \
60
60
+
--input_path "$SPARSE_DIR/0" \
61
61
+
--output_path "$SPARSE_DIR/txt" \
62
62
+
--output_type TXT
63
63
+
64
64
+
echo "COLMAP processing complete!"
65
65
+
echo "Camera poses are in: $SPARSE_DIR/txt/images.txt"
66
66
+
echo "Point cloud is in: $DENSE_DIR/fused.ply"
67
67
+
68
68
+
echo "Script completed successfully"