File size: 4,801 Bytes
790d9ba
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
"""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())