an eink camera running on an rpi zero 2 w

feat: add colmap scripts

dunkirk.sh 51e6bef8 9b7daf6e

verified
+205
+2
.gitignore
··· 1 + data/ 2 + PROSPECTUS.md
+135
colmap.bat
··· 1 + @echo off 2 + setlocal 3 + 4 + REM --- Windows Batch Version of inky/colmap.sh --- 5 + REM --- Modified to use CUDA for GPU acceleration --- 6 + 7 + REM Prerequisites: 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. 11 + 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 18 + 19 + REM Check if input video exists 20 + if not exist "%INPUT_VIDEO%" ( 21 + echo Error: Input video not found at %INPUT_VIDEO% 22 + exit /b 1 23 + ) 24 + 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 ) 34 + 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" 38 + if errorlevel 1 ( 39 + echo Error: ffmpeg frame extraction failed. Check ffmpeg output/log. 40 + exit /b 1 41 + ) 42 + 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 50 + if errorlevel 1 ( 51 + echo Error: COLMAP feature_extractor failed. Check COLMAP output/log. Ensure CUDA is working. 52 + exit /b 1 53 + ) 54 + 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 60 + if errorlevel 1 ( 61 + echo Error: COLMAP exhaustive_matcher failed. Check COLMAP output/log. Ensure CUDA is working. 62 + exit /b 1 63 + ) 64 + 65 + REM Step 4: Run COLMAP sparse reconstruction 66 + REM Note: The 'mapper' step primarily uses CPU. 67 + echo Running COLMAP sparse reconstruction... 68 + colmap mapper ^ 69 + --database_path "%COLMAP_DB%" ^ 70 + --image_path "%FRAMES_DIR%" ^ 71 + --output_path "%SPARSE_DIR%" 72 + if 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 + 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. 84 + exit /b 1 85 + ) 86 + 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%" 93 + if errorlevel 1 ( 94 + echo Error: COLMAP image_undistorter failed. Check COLMAP output/log. 95 + exit /b 1 96 + ) 97 + 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 103 + if errorlevel 1 ( 104 + echo Error: COLMAP patch_match_stereo failed. Check COLMAP output/log. Ensure CUDA is working. 105 + exit /b 1 106 + ) 107 + 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" 113 + if errorlevel 1 ( 114 + echo Error: COLMAP stereo_fusion failed. Check COLMAP output/log. 115 + exit /b 1 116 + ) 117 + 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" ^ 123 + --output_type TXT 124 + if errorlevel 1 ( 125 + echo Error: COLMAP model_converter failed. Check COLMAP output/log. 126 + exit /b 1 127 + ) 128 + 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 132 + 133 + echo Script completed successfully 134 + endlocal 135 + exit /b 0
+68
colmap.sh
··· 1 + #!/usr/bin/env -S nix shell --impure nixpkgs#ffmpeg nixpkgs#colmap nixpkgs#opencv4 --command bash 2 + 3 + set -euo pipefail 4 + 5 + # Define paths 6 + INPUT_VIDEO="data/input.mov" 7 + FRAMES_DIR="data/frames" 8 + COLMAP_DB="data/colmap.db" 9 + SPARSE_DIR="data/sparse" 10 + DENSE_DIR="data/dense" 11 + 12 + # Create directories 13 + mkdir -p "$FRAMES_DIR" "$SPARSE_DIR" "$DENSE_DIR" 14 + 15 + # Step 1: Extract frames from video 16 + echo "Extracting frames from video..." 17 + ffmpeg -i "$INPUT_VIDEO" -q:v 1 "$FRAMES_DIR/frame_%04d.jpg" 18 + 19 + # Step 2: Run COLMAP feature extraction (CPU only) 20 + echo "Running COLMAP feature extraction..." 21 + colmap feature_extractor \ 22 + --database_path "$COLMAP_DB" \ 23 + --image_path "$FRAMES_DIR" \ 24 + --ImageReader.camera_model SIMPLE_RADIAL \ 25 + --SiftExtraction.use_gpu 0 26 + 27 + # Step 3: Run COLMAP feature matching (CPU only) 28 + echo "Running COLMAP feature matching..." 29 + colmap exhaustive_matcher \ 30 + --database_path "$COLMAP_DB" \ 31 + --SiftMatching.use_gpu 0 32 + 33 + # Step 4: Run COLMAP sparse reconstruction 34 + echo "Running COLMAP sparse reconstruction..." 35 + colmap mapper \ 36 + --database_path "$COLMAP_DB" \ 37 + --image_path "$FRAMES_DIR" \ 38 + --output_path "$SPARSE_DIR" 39 + 40 + # Step 5: Run COLMAP dense reconstruction 41 + echo "Running COLMAP image undistorter..." 42 + colmap image_undistorter \ 43 + --image_path "$FRAMES_DIR" \ 44 + --input_path "$SPARSE_DIR/0" \ 45 + --output_path "$DENSE_DIR" 46 + 47 + echo "Running COLMAP patch matching (CPU only)..." 48 + colmap patch_match_stereo \ 49 + --workspace_path "$DENSE_DIR" \ 50 + --PatchMatchStereo.gpu_index -1 51 + 52 + echo "Running COLMAP stereo fusion..." 53 + colmap stereo_fusion \ 54 + --workspace_path "$DENSE_DIR" \ 55 + --output_path "$DENSE_DIR/fused.ply" 56 + 57 + # Output camera pose information for dithering 58 + echo "Extracting camera pose information..." 59 + colmap model_converter \ 60 + --input_path "$SPARSE_DIR/0" \ 61 + --output_path "$SPARSE_DIR/txt" \ 62 + --output_type TXT 63 + 64 + echo "COLMAP processing complete!" 65 + echo "Camera poses are in: $SPARSE_DIR/txt/images.txt" 66 + echo "Point cloud is in: $DENSE_DIR/fused.ply" 67 + 68 + echo "Script completed successfully"