"""Push one image through the pipeline and report what it found — wall-focused. Usage (from backend/floor-visualizer, with the server running): python scripts/wall_smoke_test.py python scripts/wall_smoke_test.py path/to/room.jpg python scripts/wall_smoke_test.py path/to/room.jpg --base https://xxx.trycloudflare.com Prints the per-stage timings, then one line per detected surface. The wall lines are the interesting ones: uv=no -> the wall is on a single-matrix transform, so tile scale comes from its bounding box rather than from measured geometry mapping=wall-contour-homography -> the metric fit was rejected entirely mapping=surface-uv -> per-pixel UV, same treatment as the floor """ from __future__ import annotations import argparse import io import json import sys import time import zipfile from pathlib import Path import requests REPO_ROOT = Path(__file__).resolve().parents[3] DEFAULT_IMAGE = ( REPO_ROOT / "frontend" / "viz2d-demo" / "src" / "assets" / "presets" / "bathroom.jpg" ) # localtunnel serves a password interstitial to browsers; this header opts out. HEADERS = {"bypass-tunnel-reminder": "1", "ngrok-skip-browser-warning": "true"} def main() -> int: parser = argparse.ArgumentParser() parser.add_argument("image", nargs="?", default=str(DEFAULT_IMAGE)) parser.add_argument("--base", default="http://localhost:8002") parser.add_argument("--timeout", type=int, default=900, help="seconds to wait for the job") args = parser.parse_args() image_path = Path(args.image) if not image_path.exists(): print(f"Image not found: {image_path}") return 1 base = args.base.rstrip("/") print(f"POST {base}/viz2d/convert ({image_path.name})") with image_path.open("rb") as handle: response = requests.post( f"{base}/viz2d/convert", files={"file": (image_path.name, handle, "image/jpeg")}, headers=HEADERS, timeout=180, ) response.raise_for_status() job = response.json() job_id = job["id"] print(f"job {job_id}\n") deadline = time.time() + args.timeout last = None while job.get("status") not in ("COMPLETED", "FAILED"): if time.time() > deadline: print(f"\nTimed out after {args.timeout}s (status={job.get('status')}).") return 1 time.sleep(2) job = requests.get(f"{base}/viz2d/jobs/{job_id}", headers=HEADERS, timeout=60).json() line = f" {job.get('status', '?'):<14} {job.get('progress', 0):>3}% {job.get('message', '')}" if line != last: print(line) last = line if job.get("status") == "FAILED": print(f"\nFAILED: {job.get('error')}") return 1 print(f"\nCompleted in {job.get('durationMs')} ms") for stage in job.get("pipelineStages", []): print(f" {stage['name']:<34} {stage['elapsed_s']:>7.2f}s {stage.get('detail', '')}") blob = requests.get(f"{base}/viz2d/jobs/{job_id}/file", headers=HEADERS, timeout=300).content meta = json.loads(zipfile.ZipFile(io.BytesIO(blob)).read("metadata.json")) print(f"\nBundle: {meta['width']}x{meta['height']}, {len(meta['segments'])} segment(s)") walls = 0 for segment in meta["segments"]: info = segment.get("metadata", {}) name = segment.get("className", "?") if name == "wall": walls += 1 pixels = info.get("surfacePixels") or info.get("wallPixels") or 0 width = info.get("surfaceWidthMeters") height = info.get("surfaceHeightMeters") size = ( f"{width:.2f}x{height:.2f}m" if isinstance(width, (int, float)) and isinstance(height, (int, float)) else "n/a" ) coverage = info.get("surfaceUvCoverage") print( f" [{segment.get('id')}] {name:<6} " f"px={pixels:<8} " f"uv={'yes' if segment.get('surfaceUv') else 'no':<4} " f"cov={coverage if coverage is None else round(float(coverage), 4)!s:<8} " f"mapping={str(info.get('textureMappingMode')):<26} " f"conf={info.get('geometryConfidence')} " f"size={size}" ) print(f"\n{walls} wall segment(s).") debug = requests.get(f"{base}/viz2d/jobs/{job_id}/debug", headers=HEADERS, timeout=60) if debug.ok: stages = debug.json().get("stages", []) print(f"Debug artifacts: {len(stages)} stage(s) at data/jobs/{job_id}.debug/") else: print("Debug artifacts unavailable (DEBUG_ARTIFACTS_ENABLED off?).") print(f"\nJOB_ID={job_id}") return 0 if __name__ == "__main__": sys.exit(main())