an eink camera running on an rpi zero 2 w
at main 4.8 kB view raw
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 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 Set COLMAP path (modify this path to match your COLMAP location) 13set COLMAP_PATH=C:\Users\kiera\Downloads\colmap-x64-windows-cuda\colmap.bat 14 15REM Define paths (using backslashes for Windows compatibility) 16set INPUT_VIDEO=data\input.mov 17set FRAMES_DIR=data\frames 18set COLMAP_DB=data\colmap.db 19set SPARSE_DIR=data\sparse 20set DENSE_DIR=data\dense 21 22REM Check if input video exists 23if not exist "%INPUT_VIDEO%" ( 24 echo Error: Input video not found at %INPUT_VIDEO% 25 exit /b 1 26) 27 28REM Create directories 29echo Creating directories... 30if not exist "data" mkdir "data" 31if not exist "%FRAMES_DIR%" mkdir "%FRAMES_DIR%" 32if errorlevel 1 ( echo Failed to create %FRAMES_DIR%. & exit /b 1 ) 33if not exist "%SPARSE_DIR%" mkdir "%SPARSE_DIR%" 34if errorlevel 1 ( echo Failed to create %SPARSE_DIR%. & exit /b 1 ) 35if not exist "%DENSE_DIR%" mkdir "%DENSE_DIR%" 36if errorlevel 1 ( echo Failed to create %DENSE_DIR%. & exit /b 1 ) 37 38REM Step 1: Extract frames from video 39echo Extracting frames from video... 40ffmpeg -i "%INPUT_VIDEO%" -q:v 1 "%FRAMES_DIR%\frame_%%04d.jpg" 41if errorlevel 1 ( 42 echo Error: ffmpeg frame extraction failed. Check ffmpeg output/log. 43 exit /b 1 44) 45 46REM Step 2: Run COLMAP feature extraction (Using CUDA GPU) 47echo Running COLMAP feature extraction (CUDA)... 48"%COLMAP_PATH%" feature_extractor ^ 49 --database_path "%COLMAP_DB%" ^ 50 --image_path "%FRAMES_DIR%" ^ 51 --ImageReader.camera_model SIMPLE_RADIAL ^ 52 --SiftExtraction.use_gpu 1 53if errorlevel 1 ( 54 echo Error: COLMAP feature_extractor failed. Check COLMAP output/log. Ensure CUDA is working. 55 exit /b 1 56) 57 58REM Step 3: Run COLMAP feature matching (Using CUDA GPU) 59echo Running COLMAP feature matching (CUDA)... 60"%COLMAP_PATH%" exhaustive_matcher ^ 61 --database_path "%COLMAP_DB%" ^ 62 --SiftMatching.use_gpu 1 63if errorlevel 1 ( 64 echo Error: COLMAP exhaustive_matcher failed. Check COLMAP output/log. Ensure CUDA is working. 65 exit /b 1 66) 67 68REM Step 4: Run COLMAP sparse reconstruction 69REM Note: The 'mapper' step primarily uses CPU. 70echo Running COLMAP sparse reconstruction... 71"%COLMAP_PATH%" mapper ^ 72 --database_path "%COLMAP_DB%" ^ 73 --image_path "%FRAMES_DIR%" ^ 74 --output_path "%SPARSE_DIR%" 75if errorlevel 1 ( 76 echo Warning: COLMAP mapper returned an error code (%ERRORLEVEL%), but proceeding. Check COLMAP output/log. 77 REM Mapper might "fail" (e.g., if few matches) but sometimes produces usable results. 78 REM More robust checking might be needed depending on COLMAP's specific exit codes. 79) 80 81REM Check if the expected output directory from mapper exists 82REM COLMAP often creates numbered subdirectories (0, 1, ...) for different models. 83REM We assume the first model (0) is the one we want. 84if not exist "%SPARSE_DIR%\0" ( 85 echo Error: Sparse reconstruction output directory (%SPARSE_DIR%\0) not found. 86 echo Mapper likely failed to produce a valid reconstruction. Check COLMAP output/log. 87 exit /b 1 88) 89 90REM Step 5: Run COLMAP dense reconstruction 91echo Running COLMAP image undistorter... 92"%COLMAP_PATH%" image_undistorter ^ 93 --image_path "%FRAMES_DIR%" ^ 94 --input_path "%SPARSE_DIR%\0" ^ 95 --output_path "%DENSE_DIR%" 96if errorlevel 1 ( 97 echo Error: COLMAP image_undistorter failed. Check COLMAP output/log. 98 exit /b 1 99) 100 101echo Running COLMAP patch matching (Using CUDA GPU)... 102REM Use --PatchMatchStereo.gpu_index 0 to select the first CUDA device. Change if needed. 103"%COLMAP_PATH%" patch_match_stereo ^ 104 --workspace_path "%DENSE_DIR%" ^ 105 --PatchMatchStereo.gpu_index 0 106if errorlevel 1 ( 107 echo Error: COLMAP patch_match_stereo failed. Check COLMAP output/log. Ensure CUDA is working. 108 exit /b 1 109) 110 111echo Running COLMAP stereo fusion... 112REM Note: Stereo fusion is primarily CPU-bound. 113"%COLMAP_PATH%" stereo_fusion ^ 114 --workspace_path "%DENSE_DIR%" ^ 115 --output_path "%DENSE_DIR%\fused.ply" 116if errorlevel 1 ( 117 echo Error: COLMAP stereo_fusion failed. Check COLMAP output/log. 118 exit /b 1 119) 120 121REM Output camera pose information 122echo Extracting camera pose information... 123"%COLMAP_PATH%" model_converter ^ 124 --input_path "%SPARSE_DIR%\0" ^ 125 --output_path "%SPARSE_DIR%\txt" ^ 126 --output_type TXT 127if errorlevel 1 ( 128 echo Error: COLMAP model_converter failed. Check COLMAP output/log. 129 exit /b 1 130) 131 132echo COLMAP processing complete! 133echo Camera poses are in: %SPARSE_DIR%\txt\images.txt 134echo Dense point cloud is in: %DENSE_DIR%\fused.ply 135 136echo Script completed successfully 137endlocal 138exit /b 0