Commit 2c82cb3d authored by Andrey Filippov's avatar Andrey Filippov

CLAUDE: Add OpenMVS CLI pipeline script

Shell wrapper: elphel_to_colmap.py → InterfaceCOLMAP →
DensifyPointCloud → ReconstructMesh → RefineMesh → TextureMesh.
Configurable via OPENMVS_BIN, NUM_THREADS, HFOV env vars.
Includes installation note for building OpenMVS from source.
Co-authored-by: 's avatarClaude <claude@elphel.com>
parent c7ec55ec
#!/usr/bin/env bash
# -----------------------------------------------------------------------------
# run_openmvs_pipeline.sh — Elphel LWIR-16 → OpenMVS full pipeline
#
# Copyright (C) 2026 Elphel, Inc.
# -----------------------------------------------------------------------------
#
# run_openmvs_pipeline.sh is free software: you can redistribute it and/or
# modify it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
# -----------------------------------------------------------------------------
#
# Full pipeline:
#
# 1. Python bridge (elphel_to_colmap.py)
# Elphel *-TERRAIN-DISP-MERGED.tiff + *-INTERFRAME.corr-xml
# → COLMAP sparse model directory (cameras.txt, images.txt, PNGs)
#
# 2. InterfaceCOLMAP
# COLMAP dir → OpenMVS scene.mvs
#
# 3. DensifyPointCloud
# scene.mvs → scene_dense.mvs + scene_dense.ply
#
# 4. ReconstructMesh
# scene_dense.mvs → scene_dense_mesh.mvs + .ply
#
# 5. RefineMesh
# scene_dense_mesh.mvs → scene_dense_mesh_refine.mvs + .ply
#
# 6. TextureMesh
# scene_dense_mesh_refine.mvs → scene_dense_mesh_refine_texture.obj + .mtl + .png
#
# Usage:
# bash scripts/run_openmvs_pipeline.sh \
# --tiff /path/to/<ts>-TERRAIN-DISP-MERGED.tiff \
# --xml /path/to/<ts>-INTERFRAME.corr-xml \
# --out /tmp/mvs_run
#
# Optional environment variable overrides:
# OPENMVS_BIN directory containing InterfaceCOLMAP, DensifyPointCloud, …
# default: search PATH, then /opt/OpenMVS/bin
# PYTHON python3 interpreter (default: python3)
# NUM_THREADS passed to all OpenMVS tools as --max-threads N
# default: number of physical CPU cores
#
# Installation note (Debian/Ubuntu):
# sudo apt install libopenmvs-tools # if packaged for your distro
# OR build from source:
# https://github.com/cdcseacave/openMVS/wiki/Building
# Typical build + install:
# cmake -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=/opt/OpenMVS ..
# make -j$(nproc) && sudo make install
# -----------------------------------------------------------------------------
set -euo pipefail
# ── Configurable defaults ────────────────────────────────────────────────────
OPENMVS_BIN="${OPENMVS_BIN:-}"
PYTHON="${PYTHON:-python3}"
NUM_THREADS="${NUM_THREADS:-$(nproc)}"
HFOV="${HFOV:-32.0}"
SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
REPO_ROOT="$(cd "$SCRIPT_DIR/.." && pwd)"
# ── Argument parsing ─────────────────────────────────────────────────────────
usage() {
echo "Usage: $0 --tiff <tiff> --xml <xml> --out <dir> [--hfov <deg>]" >&2
exit 1
}
TIFF=""; XML=""; OUT=""
while [[ $# -gt 0 ]]; do
case "$1" in
--tiff) TIFF="$2"; shift 2 ;;
--xml) XML="$2"; shift 2 ;;
--out) OUT="$2"; shift 2 ;;
--hfov) HFOV="$2"; shift 2 ;;
*) usage ;;
esac
done
[[ -n "$TIFF" && -n "$XML" && -n "$OUT" ]] || usage
# ── Locate OpenMVS binaries ──────────────────────────────────────────────────
find_openmvs_bin() {
local tool="InterfaceCOLMAP"
if [[ -n "$OPENMVS_BIN" ]]; then
echo "$OPENMVS_BIN"; return
fi
local p
p="$(command -v "$tool" 2>/dev/null)" && { dirname "$p"; return; }
for d in /opt/OpenMVS/bin /usr/local/bin /usr/bin; do
[[ -x "$d/$tool" ]] && { echo "$d"; return; }
done
echo ""
}
MVS_BIN="$(find_openmvs_bin)"
if [[ -z "$MVS_BIN" ]]; then
echo "ERROR: OpenMVS binaries not found." >&2
echo " Set OPENMVS_BIN=/path/to/OpenMVS/bin or install OpenMVS." >&2
echo " See the installation note at the top of this script." >&2
exit 1
fi
echo "OpenMVS binaries: $MVS_BIN"
# ── Helper ───────────────────────────────────────────────────────────────────
run() {
echo ""
echo "── $* ──"
"$@"
}
# ── Step 1: Python bridge ────────────────────────────────────────────────────
COLMAP_DIR="$OUT/colmap"
run "$PYTHON" "$REPO_ROOT/scripts/elphel_to_colmap.py" \
--tiff "$TIFF" \
--xml "$XML" \
--out "$COLMAP_DIR" \
--hfov "$HFOV"
# ── Step 2: InterfaceCOLMAP ─────────────────────────────────────────────────
MVS_DIR="$OUT/mvs"
mkdir -p "$MVS_DIR"
run "$MVS_BIN/InterfaceCOLMAP" \
--input-path "$COLMAP_DIR" \
--output-file "$MVS_DIR/scene.mvs" \
--image-folder "$COLMAP_DIR/images"
# ── Step 3: DensifyPointCloud ────────────────────────────────────────────────
run "$MVS_BIN/DensifyPointCloud" \
--input-file "$MVS_DIR/scene.mvs" \
--output-file "$MVS_DIR/scene_dense.mvs" \
--max-threads "$NUM_THREADS"
# ── Step 4: ReconstructMesh ──────────────────────────────────────────────────
run "$MVS_BIN/ReconstructMesh" \
--input-file "$MVS_DIR/scene_dense.mvs" \
--output-file "$MVS_DIR/scene_mesh.mvs" \
--max-threads "$NUM_THREADS"
# ── Step 5: RefineMesh ───────────────────────────────────────────────────────
run "$MVS_BIN/RefineMesh" \
--input-file "$MVS_DIR/scene_mesh.mvs" \
--output-file "$MVS_DIR/scene_mesh_refine.mvs" \
--max-threads "$NUM_THREADS"
# ── Step 6: TextureMesh ──────────────────────────────────────────────────────
run "$MVS_BIN/TextureMesh" \
--input-file "$MVS_DIR/scene_mesh_refine.mvs" \
--output-file "$MVS_DIR/scene_texture.mvs" \
--max-threads "$NUM_THREADS"
echo ""
echo "Done. Textured mesh: $MVS_DIR/scene_texture.obj (+ .mtl + .png)"
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment