@echo off

rem Set the path to your COLMAP executable here
set COLMAP_EXE=bin\colmap.exe


rem start from a clean workspace
if exist workspace rmdir /s /q workspace

mkdir workspace
mkdir workspace\sparse
mkdir workspace\dense

echo.
echo Feature extraction
"%COLMAP_EXE%" feature_extractor --database_path workspace\database.db --image_path images --ImageReader.single_camera_per_folder 1

echo.
echo Exhaustive matching
"%COLMAP_EXE%" exhaustive_matcher --database_path workspace\database.db

echo.
echo Mapper (sparse reconstruction)
"%COLMAP_EXE%" mapper --database_path workspace\database.db --image_path images --output_path workspace\sparse

echo.
echo Image undistortion
"%COLMAP_EXE%" image_undistorter --image_path images --input_path workspace\sparse\0 --output_path workspace\dense --output_type COLMAP

echo.
echo PatchMatch stereo
"%COLMAP_EXE%" patch_match_stereo --workspace_path workspace\dense --workspace_format COLMAP --PatchMatchStereo.geom_consistency true

echo.
echo Stereo fusion
"%COLMAP_EXE%" stereo_fusion --workspace_path workspace\dense --workspace_format COLMAP --input_type geometric --output_path workspace\dense\fused.ply

echo.
echo Poisson meshing
"%COLMAP_EXE%" poisson_mesher --input_path workspace\dense\fused.ply --output_path workspace\dense\meshed-poisson.ply

echo.
echo Creating readable data for later processing
"%COLMAP_EXE%" model_converter --input_path workspace/sparse/0 --output_path workspace/sparse/0 --output_type TXT

echo.
echo Done.
pause