github-actions[bot] commited on
Commit
d3ceecd
·
1 Parent(s): d7b5c2a

Automated Deploy: 707c41cb8e6ee482f3f3dfc71e1f2689f4362864

Browse files
config/runtime.py CHANGED
@@ -6,7 +6,7 @@ ENABLE_FLOOR_MASK_CLEANUP = config_bool("ENABLE_FLOOR_MASK_CLEANUP", "runtime",
6
  ENABLE_DEPTH_ESTIMATION = config_bool("ENABLE_DEPTH_ESTIMATION", "runtime", "enable_depth_estimation", "1")
7
  ENABLE_PLANE_FIT = config_bool("ENABLE_PLANE_FIT", "runtime", "enable_plane_fit", "1")
8
  ENABLE_MULTI_PLANE_SURFACES = config_bool("ENABLE_MULTI_PLANE_SURFACES", "runtime", "enable_multi_plane_surfaces", "1")
9
- ENABLE_WALL_SEGMENTS = config_bool("ENABLE_WALL_SEGMENTS", "runtime", "enable_wall_segments", "1")
10
  ENABLE_INTRINSIC_SHADING = config_bool("ENABLE_INTRINSIC_SHADING", "runtime", "enable_intrinsic_shading", "0")
11
  ENABLE_SHADING_TRANSFER = config_bool("ENABLE_SHADING_TRANSFER", "runtime", "enable_shading_transfer", "1")
12
  ENABLE_FAST_SHADOW_TRANSFER = config_bool(
 
6
  ENABLE_DEPTH_ESTIMATION = config_bool("ENABLE_DEPTH_ESTIMATION", "runtime", "enable_depth_estimation", "1")
7
  ENABLE_PLANE_FIT = config_bool("ENABLE_PLANE_FIT", "runtime", "enable_plane_fit", "1")
8
  ENABLE_MULTI_PLANE_SURFACES = config_bool("ENABLE_MULTI_PLANE_SURFACES", "runtime", "enable_multi_plane_surfaces", "1")
9
+ ENABLE_WALL_SEGMENTS = config_bool("ENABLE_WALL_SEGMENTS", "runtime", "enable_wall_segments", "0")
10
  ENABLE_INTRINSIC_SHADING = config_bool("ENABLE_INTRINSIC_SHADING", "runtime", "enable_intrinsic_shading", "0")
11
  ENABLE_SHADING_TRANSFER = config_bool("ENABLE_SHADING_TRANSFER", "runtime", "enable_shading_transfer", "1")
12
  ENABLE_FAST_SHADOW_TRANSFER = config_bool(
config/surface.py CHANGED
@@ -51,15 +51,6 @@ SURFACE_UV_MIN_COVERAGE = float(config_value(
51
  "SURFACE_UV_MIN_COVERAGE", "surface_mapping", "uv_min_coverage", "0.995",
52
  ))
53
 
54
- # Walls tile *behind* mounted objects, so a wall surface legitimately
55
- # contains pixels with no valid wall geometry (a TV, a mirror, a cabinet).
56
- # Holding walls to the floor's 0.995 makes every wall fail the gate as
57
- # 'incomplete-surface-uv'. The shortfall is exactly the occluded pixels,
58
- # which the occlusion mask repaints anyway, so it is not a defect.
59
- SURFACE_UV_WALL_MIN_COVERAGE = float(config_value(
60
- "SURFACE_UV_WALL_MIN_COVERAGE", "surface_mapping", "uv_wall_min_coverage", "0.90",
61
- ))
62
-
63
  SURFACE_UV_MAX_BAD_NEIGHBOR_RATIO = float(config_value(
64
  "SURFACE_UV_MAX_BAD_NEIGHBOR_RATIO", "surface_mapping", "uv_max_bad_neighbor_ratio", "0.035",
65
  ))
 
51
  "SURFACE_UV_MIN_COVERAGE", "surface_mapping", "uv_min_coverage", "0.995",
52
  ))
53
 
 
 
 
 
 
 
 
 
 
54
  SURFACE_UV_MAX_BAD_NEIGHBOR_RATIO = float(config_value(
55
  "SURFACE_UV_MAX_BAD_NEIGHBOR_RATIO", "surface_mapping", "uv_max_bad_neighbor_ratio", "0.035",
56
  ))
frontend/viz2d-demo/e2e/helpers.ts DELETED
@@ -1,80 +0,0 @@
1
- import path from "node:path";
2
- import { fileURLToPath } from "node:url";
3
- import { expect, type Page } from "@playwright/test";
4
-
5
- // The package is ESM ("type": "module"), so there is no __dirname.
6
- const here = path.dirname(fileURLToPath(import.meta.url));
7
-
8
- export const ROOM_PHOTO = path.resolve(here, "../test-images/Image 1.jpeg");
9
-
10
- /** A material with a hard grid, so a tilted or mis-scaled basis is visible. */
11
- export const GRID_TEXTURE = "Grey Checkerboard";
12
-
13
- /**
14
- * Upload a room photo and wait for the backend to finish detecting surfaces.
15
- *
16
- * The CPU pipeline takes roughly 20s, and the bundle download follows it, so
17
- * this waits on a wall card rather than on the editor shell.
18
- */
19
- export async function openEditorWithRoomPhoto(page: Page) {
20
- await page.goto("/");
21
- await page.setInputFiles('[data-testid="room-file-input"]', ROOM_PHOTO);
22
- // The editor only mounts once the pipeline returns a bundle, so both of
23
- // these wait out a full CPU detection run rather than the default timeout.
24
- await expect(page.getByTestId("visualizer-editor")).toBeVisible({ timeout: 150_000 });
25
- await expect(page.locator('[data-testid="surface-card"][data-surface-class="wall"]')).toBeVisible({
26
- timeout: 150_000,
27
- });
28
- await expect(page.getByTestId("blocking-overlay")).toHaveCount(0, { timeout: 60_000 });
29
- }
30
-
31
- /**
32
- * Select a wall by clicking the canvas where its label sits.
33
- *
34
- * The label is positioned at an anchor inside the wall's own mask, so this is
35
- * a stable way to hit a specific wall. The label itself is pointer-events-none,
36
- * so the click lands on the canvas underneath it.
37
- *
38
- * Returns the wall's label text, e.g. "Wall 1".
39
- */
40
- export async function selectWallOnCanvas(page: Page, index = 0) {
41
- const label = page.locator('[data-testid="surface-label"][data-surface-class="wall"]').nth(index);
42
- await expect(label).toBeVisible();
43
- const text = (await label.innerText()).trim();
44
- const box = await label.boundingBox();
45
- if (!box) throw new Error(`wall label ${index} has no box`);
46
- await page.mouse.click(box.x + box.width / 2, box.y + box.height / 2);
47
- return text;
48
- }
49
-
50
- /** Apply a catalog texture through the selector that a surface click opens. */
51
- export async function applyTexture(page: Page, name = GRID_TEXTURE) {
52
- const selector = page.getByTestId("texture-selector");
53
- await expect(selector).toBeVisible();
54
- await selector.locator(`[data-testid="texture-card"][data-texture-name="${name}"]`).click();
55
- await expect(page.getByTestId("blocking-overlay")).toHaveCount(0, { timeout: 60_000 });
56
- }
57
-
58
- /**
59
- * Upload a room photo and wait for detection, at a phone viewport.
60
- *
61
- * Separate from openEditorWithRoomPhoto because that one waits on a wall
62
- * surface-card, which on mobile lives inside a sheet that has not been opened
63
- * yet and so is not in the DOM at all. The Surfaces trigger is the mobile
64
- * equivalent: it enables only once a bundle has loaded.
65
- */
66
- export async function openEditorOnMobile(page: Page) {
67
- await page.goto("/");
68
- await page.setInputFiles('[data-testid="room-file-input"]', ROOM_PHOTO);
69
- await expect(page.getByTestId("visualizer-editor")).toBeVisible({ timeout: 150_000 });
70
- await expect(page.getByTestId("mobile-surfaces-trigger")).toBeEnabled({ timeout: 150_000 });
71
- await expect(page.getByTestId("blocking-overlay")).toHaveCount(0, { timeout: 60_000 });
72
- }
73
-
74
- /** Open the mobile surfaces sheet and return it. */
75
- export async function openSurfacesSheet(page: Page) {
76
- await page.getByTestId("mobile-surfaces-trigger").click();
77
- const sheet = page.getByTestId("mobile-surfaces-sheet");
78
- await expect(sheet).toBeVisible();
79
- return sheet;
80
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
frontend/viz2d-demo/e2e/wall-tile-controls.spec.ts DELETED
@@ -1,67 +0,0 @@
1
- import { expect, test } from "@playwright/test";
2
-
3
- import { applyTexture, openEditorWithRoomPhoto, selectWallOnCanvas } from "./helpers";
4
-
5
- /**
6
- * Walls used to be routed around the per-segment card list, so they never got
7
- * the Tile size / Rotation sliders the floor has. A wall whose material has a
8
- * hard grid needs them most: nothing else can correct a grid that lands tilted
9
- * or at the wrong pitch.
10
- *
11
- * The controls are shared across walls by default -- tiles are normally the
12
- * same product on every wall -- with a per-wall override for the selected wall.
13
- */
14
- test.describe("wall tile controls", () => {
15
- test("a textured wall exposes shared tile size and rotation", async ({ page }) => {
16
- await openEditorWithRoomPhoto(page);
17
- await selectWallOnCanvas(page);
18
- await applyTexture(page);
19
-
20
- const shared = page.getByTestId("wall-shared-adjustments");
21
-
22
- await expect(shared).toBeVisible();
23
- await expect(shared.getByTestId("texture-adjust-scale")).toBeVisible();
24
- await expect(shared.getByTestId("texture-adjust-rotation")).toBeVisible();
25
- });
26
-
27
- test("the shared tile size drives every textured wall", async ({ page }) => {
28
- await openEditorWithRoomPhoto(page);
29
- await selectWallOnCanvas(page);
30
- await applyTexture(page);
31
-
32
- const scale = page.getByTestId("wall-shared-adjustments").getByTestId("texture-adjust-scale");
33
- await scale.fill("2");
34
- await expect(page.getByTestId("blocking-overlay")).toHaveCount(0, { timeout: 60_000 });
35
-
36
- // Every wall carrying a texture reports the shared value back.
37
- const overrides = page.locator('[data-testid="wall-override-card"]');
38
- for (let i = 0; i < (await overrides.count()); i += 1) {
39
- await expect(overrides.nth(i).getByTestId("texture-adjust-scale")).toHaveValue("2");
40
- }
41
- await expect(scale).toHaveValue("2");
42
- });
43
-
44
- test("the override card names the wall that was clicked", async ({ page }) => {
45
- // `filteredSegments` sorts textured surfaces to the front, so numbering
46
- // walls by their position in that list renamed a wall the instant its tile
47
- // landed: you click Wall 2 and get a card that claims to adjust Wall 1.
48
- // Texturing only the second wall is what makes the reorder observable.
49
- await openEditorWithRoomPhoto(page);
50
- const label = await selectWallOnCanvas(page, 1);
51
- await applyTexture(page);
52
-
53
- await expect(page.locator('[data-testid="wall-override-card"]')).toContainText(label);
54
- });
55
-
56
- test("selecting a wall reveals controls for just that wall", async ({ page }) => {
57
- await openEditorWithRoomPhoto(page);
58
- const wallLabel = await selectWallOnCanvas(page);
59
- await applyTexture(page);
60
-
61
- const override = page.locator('[data-testid="wall-override-card"]');
62
-
63
- await expect(override).toBeVisible();
64
- await expect(override).toContainText(wallLabel);
65
- await expect(override.getByTestId("texture-adjust-rotation")).toBeVisible();
66
- });
67
- });
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
frontend/viz2d-demo/e2e/wall-tile-orientation.spec.ts DELETED
@@ -1,40 +0,0 @@
1
- import { expect, test } from "@playwright/test";
2
-
3
- import { applyTexture, openEditorWithRoomPhoto, selectWallOnCanvas } from "./helpers";
4
-
5
- /**
6
- * Every wall's tile grid must start plumb.
7
- *
8
- * When a wall has no per-pixel UV -- which is every wall on a CPU profile,
9
- * where depth estimation is off -- the auto-rotation fell through to the angle
10
- * of the mask's top edge. On a wall seen in perspective that edge is the
11
- * slanted ceiling line, so the grid opened pre-tilted by that slant.
12
- *
13
- * The homography already carries the wall's perspective, so the correct
14
- * starting rotation is zero and the user's slider moves away from there.
15
- *
16
- * This asserts on *every* wall on purpose. The first wall in this photo has an
17
- * axis-aligned quad, so its fallback angle is 0 by accident and it cannot
18
- * detect the bug; the second wall's quad is genuinely slanted.
19
- */
20
- test.describe("wall tile orientation", () => {
21
- test("every wall's tile grid starts unrotated", async ({ page }) => {
22
- await openEditorWithRoomPhoto(page);
23
-
24
- const walls = page.locator('[data-testid="surface-label"][data-surface-class="wall"]');
25
- const wallCount = await walls.count();
26
- expect(wallCount, "this photo should detect more than one wall").toBeGreaterThan(1);
27
-
28
- for (let index = 0; index < wallCount; index += 1) {
29
- const label = await selectWallOnCanvas(page, index);
30
- await applyTexture(page);
31
-
32
- const override = page.locator('[data-testid="wall-override-card"]');
33
- await expect(override, `${label} should be the selected wall`).toContainText(label);
34
- await expect(
35
- override.getByTestId("texture-adjust-rotation"),
36
- `${label} opened with a rotated tile grid`,
37
- ).toHaveValue("0");
38
- }
39
- });
40
- });
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
services/wall/components.py CHANGED
@@ -13,122 +13,24 @@ from services.geometry.multi_plane import (
13
  assign_points_to_surface_planes,
14
  fit_multi_surface_planes,
15
  geometry_point_maps,
16
- merge_coplanar_planes,
17
- merge_planes_by_point_consistency,
18
  )
19
  from services.geometry.normals import normalize_vectors
20
- from services.geometry.plane_fitting import surface_distance_threshold
21
- from services.wall.corner import straighten_piece_seams
22
- from services.wall.mask import refine_wall_component_mask, wall_region_masks
23
  from state import OCCLUDER_CLASSES, class_ids
24
  from utils import seg_class_mask
25
 
26
 
27
- def split_region_if_not_planar(region: np.ndarray, geometry: dict | None, min_area: int):
28
- """Return [region] when it is one flat wall, else split it by fitted planes.
29
-
30
- Connectivity alone is not quite enough: where two walls meet at a corner
31
- with nothing between them, segmentation bridges the corner and hands us one
32
- region covering both. Those need separating, or one warped transform gets
33
- stretched across an angle.
34
-
35
- So geometry gets a narrow, well-posed job: decide whether this region is
36
- flat. A single least-squares plane is fitted and the 90th-percentile
37
- residual measured. A real wall sits within a couple of centimetres of its
38
- own plane; a region spanning a corner does not come close. Only when the
39
- region fails that test do we fall back to multi-plane splitting.
40
- """
41
- if geometry is None:
42
- return [region]
43
- maps = geometry_point_maps(region, geometry)
44
- if maps is None:
45
- return [region]
46
-
47
- valid = maps["validMask"] & (region > 0)
48
- ys, xs = np.where(valid)
49
- if len(xs) < SURFACE_MIN_PLANE_PIXELS:
50
- return [region]
51
- points = maps["points"][ys, xs].astype(np.float32)
52
- normals = maps["normals"][ys, xs].astype(np.float32)
53
- finite = np.isfinite(points).all(axis=1) & np.isfinite(normals).all(axis=1)
54
- points, normals, ys, xs = points[finite], normals[finite], ys[finite], xs[finite]
55
- if len(points) < SURFACE_MIN_PLANE_PIXELS:
56
- return [region]
57
-
58
- threshold = surface_distance_threshold(points)
59
- centered = points - points.mean(axis=0)
60
- # Smallest-eigenvalue eigenvector of the covariance is the plane normal.
61
- _eigenvalues, eigenvectors = np.linalg.eigh(centered.T @ centered)
62
- residual = np.abs(centered @ eigenvectors[:, 0].astype(np.float32))
63
- flatness = float(np.percentile(residual, 90))
64
- print(
65
- f"[WALL_REGION] {int(region.sum())} px p90Flatness={flatness:.3f}m "
66
- f"threshold={threshold:.3f}m {'FLAT (keep whole)' if flatness <= threshold else 'not flat -> split by plane'}",
67
- flush=True,
68
- )
69
- if flatness <= threshold:
70
- return [region]
71
-
72
- lengths = np.linalg.norm(normals, axis=1)
73
- usable = lengths > 1e-4
74
- if int(usable.sum()) < SURFACE_MIN_PLANE_PIXELS:
75
- return [region]
76
- points, ys, xs = points[usable], ys[usable], xs[usable]
77
- normals = normalize_vectors(normals[usable])
78
-
79
- planes = fit_multi_surface_planes(points, normals, True, mark_floor=False)
80
- planes = merge_coplanar_planes(planes, threshold)
81
- wall_planes = [plane for plane in planes if abs(float(plane["normal"][1])) <= 0.45]
82
- if len(wall_planes) <= 1:
83
- return [region]
84
-
85
- assignment = assign_points_to_surface_planes(points, normals, wall_planes, True)
86
- assignment, wall_planes = merge_planes_by_point_consistency(
87
- points, assignment, wall_planes, threshold
88
- )
89
- if len(wall_planes) <= 1:
90
- return [region]
91
-
92
- pieces = []
93
- for plane_index in range(len(wall_planes)):
94
- selected = assignment == plane_index
95
- if int(selected.sum()) < min_area:
96
- continue
97
- piece = np.zeros_like(region)
98
- piece[ys[selected], xs[selected]] = 1
99
- pieces.append((plane_index, piece))
100
- if not pieces:
101
- return [region]
102
-
103
- # Per-pixel assignment is the wrong tool for the seam *between* these
104
- # pieces. At the corner every plane is equidistant, so the score collapses
105
- # onto blended depth normals and the boundary ends up both biased and
106
- # ragged. Put each seam back on the line where its two planes actually
107
- # intersect -- see services/wall/corner.py for the measurements.
108
- return straighten_piece_seams(pieces, wall_planes, maps.get("intrinsics"), min_area)
109
-
110
-
111
- def wall_surface_components(seg_map: np.ndarray, min_area: int, geometry: dict | None = None,
112
- image_rgb: np.ndarray | None = None):
113
  """Create clean, independently renderable wall regions.
114
 
115
  Semantic wall predictions often bridge across corners and openings. Removing
116
  protected classes before connected-component analysis prevents one warped
117
  transform from being applied to several physically different walls.
118
  """
119
- # Components may occupy the wall itself plus anything mounted on it; those
120
- # objects are re-drawn over the tile via the segment occlusion mask instead
121
- # of being cut out of the surface. See services/wall/mask.py.
122
- wall_raw, barrier_mask, reclaimable_mask = wall_region_masks(seg_map)
123
-
124
- wall = wall_raw.copy()
125
  protected = seg_class_mask(seg_map, class_ids(OCCLUDER_CLASSES | {
126
  "door", "window", "column", "base", "railing", "ceiling",
127
  "building", "painting", "mirror", "curtain",
128
  }))
129
- # Wide enough to close the gap a wall-mounted TV or mirror leaves behind,
130
- # narrow enough that a doorway or a room corner still separates two walls.
131
- bridge_kernel_size = max(3, int(round(min(seg_map.shape[:2]) * 0.05))) | 1
132
  radius = max(1, int(round(min(seg_map.shape[:2]) * 0.006)))
133
  kernel = cv2.getStructuringElement(cv2.MORPH_ELLIPSE, (radius * 2 + 1, radius * 2 + 1))
134
  protected = cv2.dilate(protected, kernel, iterations=1)
@@ -137,68 +39,54 @@ def wall_surface_components(seg_map: np.ndarray, min_area: int, geometry: dict |
137
  wall = cv2.morphologyEx(wall, cv2.MORPH_OPEN, kernel)
138
  wall[protected > 0] = 0
139
 
140
- # --- Stage 1: connectivity decides what counts as one wall ----------------
141
- # Geometry used to decide this, by fitting planes over every wall pixel and
142
- # assigning each pixel to its nearest plane. Per-pixel normals from depth are
143
- # noisy, so that assignment banded single walls into vertical depth slabs: a
144
- # living room with three walls produced three planes but five segments, each
145
- # with its own UV frame, so the tile grid restarted and rotated at every
146
- # seam. Spatial connectivity is far more reliable for "is this one wall",
147
- # because walls are separated by corners, which are visible discontinuities.
148
- bridge = cv2.morphologyEx(
149
- wall,
150
- cv2.MORPH_CLOSE,
151
- cv2.getStructuringElement(cv2.MORPH_ELLIPSE, (bridge_kernel_size, bridge_kernel_size)),
152
- )
153
- region_count, region_labels, _region_stats, _ = cv2.connectedComponentsWithStats(
154
- bridge, connectivity=8
155
- )
156
- regions = []
157
- for region_id in range(1, region_count):
158
- region = ((region_labels == region_id) & (wall > 0)).astype(np.uint8)
159
- if int(region.sum()) >= min_area:
160
- regions.append(region)
161
- print(f"[WALL_COMPONENTS] {len(regions)} connected wall region(s)", flush=True)
162
-
163
- # --- Stage 2: geometry only splits a region that is not actually flat -----
164
- # components is a list of (area, mask) pairs; the repair pass below sorts on
165
- # the area, so pieces must be paired up rather than appended bare.
166
  components = []
167
- for region in regions:
168
- for piece in split_region_if_not_planar(region, geometry, min_area):
169
- area = int(piece.sum())
170
- if area >= min_area:
171
- components.append((area, piece.astype(np.uint8)))
172
-
173
- # --- Repair pass -------------------------------------------------------
174
- # Splitting above deliberately runs on the protected-subtracted mask, so one
175
- # warped transform is never stretched across a corner or an opening. Now
176
- # that the split is settled, each component reclaims the holes that plane
177
- # assignment and protection punched through it.
178
- #
179
- # Largest first, subtracting whatever earlier components already claimed, so
180
- # the refined masks stay disjoint — otherwise the edge-repair dilation would
181
- # let two walls overlap at a corner and that seam would be tiled twice.
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
182
  components.sort(key=lambda item: item[0], reverse=True)
183
- claimed = np.zeros(wall_raw.shape[:2], dtype=bool)
184
- refined_components = []
185
- for _, component_mask in components:
186
- refined, _metadata = refine_wall_component_mask(
187
- component_mask, wall_raw, reclaimable_mask, barrier_mask, image_rgb
188
- )
189
- refined[claimed] = 0
190
- area = int(refined.sum())
191
- if area < min_area:
192
- continue
193
- claimed |= refined.astype(bool)
194
- refined_components.append((area, refined))
195
-
196
- if refined_components:
197
- refined_components.sort(key=lambda item: item[0], reverse=True)
198
- print(
199
- f"[WALL_COMPONENTS] emitting {len(refined_components)} wall segment(s): "
200
- f"{[area for area, _ in refined_components]} px",
201
- flush=True,
202
- )
203
- return refined_components, protected
204
  return components, protected
 
13
  assign_points_to_surface_planes,
14
  fit_multi_surface_planes,
15
  geometry_point_maps,
 
 
16
  )
17
  from services.geometry.normals import normalize_vectors
 
 
 
18
  from state import OCCLUDER_CLASSES, class_ids
19
  from utils import seg_class_mask
20
 
21
 
22
+ def wall_surface_components(seg_map: np.ndarray, min_area: int, geometry: dict | None = None):
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
23
  """Create clean, independently renderable wall regions.
24
 
25
  Semantic wall predictions often bridge across corners and openings. Removing
26
  protected classes before connected-component analysis prevents one warped
27
  transform from being applied to several physically different walls.
28
  """
29
+ wall = seg_class_mask(seg_map, class_ids({"wall"}))
 
 
 
 
 
30
  protected = seg_class_mask(seg_map, class_ids(OCCLUDER_CLASSES | {
31
  "door", "window", "column", "base", "railing", "ceiling",
32
  "building", "painting", "mirror", "curtain",
33
  }))
 
 
 
34
  radius = max(1, int(round(min(seg_map.shape[:2]) * 0.006)))
35
  kernel = cv2.getStructuringElement(cv2.MORPH_ELLIPSE, (radius * 2 + 1, radius * 2 + 1))
36
  protected = cv2.dilate(protected, kernel, iterations=1)
 
39
  wall = cv2.morphologyEx(wall, cv2.MORPH_OPEN, kernel)
40
  wall[protected > 0] = 0
41
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
42
  components = []
43
+ if geometry is not None:
44
+ maps = geometry_point_maps(wall, geometry)
45
+ if maps is not None:
46
+ valid = maps["validMask"] & (wall > 0)
47
+ ys, xs = np.where(valid)
48
+ if len(xs) >= SURFACE_MIN_PLANE_PIXELS:
49
+ points = maps["points"][ys, xs].astype(np.float32)
50
+ normals = maps["normals"][ys, xs].astype(np.float32)
51
+ finite = np.isfinite(points).all(axis=1) & np.isfinite(normals).all(axis=1)
52
+ points, normals, ys, xs = points[finite], normals[finite], ys[finite], xs[finite]
53
+ if len(points) >= SURFACE_MIN_PLANE_PIXELS:
54
+ normals_reliable = np.linalg.norm(normals, axis=1) > 1e-4
55
+ if normals_reliable.sum() >= SURFACE_MIN_PLANE_PIXELS:
56
+ points = points[normals_reliable]
57
+ normals = normalize_vectors(normals[normals_reliable])
58
+ ys, xs = ys[normals_reliable], xs[normals_reliable]
59
+ planes = fit_multi_surface_planes(points, normals, True)
60
+ wall_planes = [
61
+ plane for plane in planes
62
+ if abs(float(plane["normal"][1])) <= 0.45
63
+ ]
64
+ if wall_planes:
65
+ assignment = assign_points_to_surface_planes(
66
+ points, normals, wall_planes, True
67
+ )
68
+ for plane_index in range(len(wall_planes)):
69
+ selected = assignment == plane_index
70
+ if int(selected.sum()) < min_area:
71
+ continue
72
+ plane_mask = np.zeros_like(wall)
73
+ plane_mask[ys[selected], xs[selected]] = 1
74
+ count, labels, stats, _ = cv2.connectedComponentsWithStats(
75
+ plane_mask, connectivity=8
76
+ )
77
+ for component_id in range(1, count):
78
+ area = int(stats[component_id, cv2.CC_STAT_AREA])
79
+ if area >= min_area:
80
+ components.append((area, (labels == component_id).astype(np.uint8)))
81
+
82
+ # Geometry can be unavailable or too noisy. In that case retain the safe
83
+ # semantic connected-component fallback instead of emitting no walls.
84
+ if not components:
85
+ count, labels, stats, _ = cv2.connectedComponentsWithStats(wall, connectivity=8)
86
+ for component_id in range(1, count):
87
+ area = int(stats[component_id, cv2.CC_STAT_AREA])
88
+ if area < min_area:
89
+ continue
90
+ components.append((area, (labels == component_id).astype(np.uint8)))
91
  components.sort(key=lambda item: item[0], reverse=True)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
92
  return components, protected
services/wall/plane.py CHANGED
@@ -16,29 +16,14 @@ from services.geometry.plane_fitting import (
16
  fit_metric_floor_transform,
17
  )
18
 
19
- # Assumed floor-to-ceiling height, in metres, for a wall with no depth to
20
- # measure. Only the wall's *aspect* can be recovered from a single view without
21
- # metric geometry, so this sets the absolute scale; the metric fit overrides
22
- # both extents whenever it succeeds.
23
- WALL_HEIGHT_PRIOR_METERS = 2.4
24
 
25
-
26
- def estimate_wall_plane(
27
- mask: np.ndarray,
28
- geometry: dict | None = None,
29
- vertical_ref: np.ndarray | None = None,
30
- ):
31
  """Return a stable image-space homography for a semantic wall mask.
32
 
33
  Walls do not currently have metric depth fitting, so use the visible wall
34
  contour as the source quad and its bounding rectangle as the planar target.
35
  This preserves perspective convergence while keeping physical tile sizes
36
  deterministic until wall-specific depth calibration is available.
37
-
38
- `vertical_ref` is which direction gravity-up points, in the same frame as
39
- the geometry's points. Geometry providers work in camera coordinates, so
40
- without it the metric fit assumes camera +Y is up and rotates the wall's
41
- tile grid by the camera's roll. Callers should pass the floor normal.
42
  """
43
  ys, xs = np.where(mask > 0)
44
  if len(xs) < 1000:
@@ -78,23 +63,6 @@ def estimate_wall_plane(
78
  if x2 - x1 < 20 or y2 - y1 < 20:
79
  return None, None
80
 
81
- # Measure the wall along its own edges, averaging opposite pairs.
82
- #
83
- # The axis-aligned bounding box was standing in for these, which overstates
84
- # a tilted wall: a slanted mask falls through to `minAreaRect`, whose
85
- # corners can sit well outside the image, and the box around that rotated
86
- # rect is far wider than the wall. Edge lengths are unaffected by the tilt
87
- # and by corners leaving the frame, and for an axis-aligned quad they are
88
- # exactly the box dimensions, so only genuinely tilted walls move.
89
- quad_width = 0.5 * (
90
- float(np.linalg.norm(ordered[1] - ordered[0]))
91
- + float(np.linalg.norm(ordered[2] - ordered[3]))
92
- )
93
- quad_height = 0.5 * (
94
- float(np.linalg.norm(ordered[3] - ordered[0]))
95
- + float(np.linalg.norm(ordered[2] - ordered[1]))
96
- )
97
-
98
  destination = np.float32([[x1, y1], [x2, y1], [x2, y2], [x1, y2]])
99
  homography = cv2.getPerspectiveTransform(ordered, destination).flatten().tolist()
100
  metric_geometry = None
@@ -109,7 +77,6 @@ def estimate_wall_plane(
109
  geometry.get("intrinsics"),
110
  geometry.get("provider", GeometryProvider.METRIC_DEPTH),
111
  surface_kind="wall",
112
- vertical_ref=vertical_ref,
113
  )
114
  if metric_geometry is None:
115
  metric_geometry = estimate_metric_floor_transform(
@@ -118,7 +85,6 @@ def estimate_wall_plane(
118
  geometry.get("provider", GeometryProvider.DEPTH_ANYTHING),
119
  geometry.get("intrinsics"),
120
  surface_kind="wall",
121
- vertical_ref=vertical_ref,
122
  )
123
 
124
  plane = {
@@ -132,10 +98,8 @@ def estimate_wall_plane(
132
  "floorTransform": None,
133
  "surfaceTransform": None,
134
  "surfaceType": SurfaceType.WALL,
135
- "surfaceWidthMeters": max(
136
- 0.5, WALL_HEIGHT_PRIOR_METERS * quad_width / max(quad_height, 1.0)
137
- ),
138
- "surfaceHeightMeters": WALL_HEIGHT_PRIOR_METERS,
139
  "metersPerUnit": None,
140
  "cameraIntrinsics": None,
141
  "camera": {"focalLength": float(max(h, w) * 0.95), "horizonY": y1, "confidence": 0.45},
 
16
  fit_metric_floor_transform,
17
  )
18
 
 
 
 
 
 
19
 
20
+ def estimate_wall_plane(mask: np.ndarray, geometry: dict | None = None):
 
 
 
 
 
21
  """Return a stable image-space homography for a semantic wall mask.
22
 
23
  Walls do not currently have metric depth fitting, so use the visible wall
24
  contour as the source quad and its bounding rectangle as the planar target.
25
  This preserves perspective convergence while keeping physical tile sizes
26
  deterministic until wall-specific depth calibration is available.
 
 
 
 
 
27
  """
28
  ys, xs = np.where(mask > 0)
29
  if len(xs) < 1000:
 
63
  if x2 - x1 < 20 or y2 - y1 < 20:
64
  return None, None
65
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
66
  destination = np.float32([[x1, y1], [x2, y1], [x2, y2], [x1, y2]])
67
  homography = cv2.getPerspectiveTransform(ordered, destination).flatten().tolist()
68
  metric_geometry = None
 
77
  geometry.get("intrinsics"),
78
  geometry.get("provider", GeometryProvider.METRIC_DEPTH),
79
  surface_kind="wall",
 
80
  )
81
  if metric_geometry is None:
82
  metric_geometry = estimate_metric_floor_transform(
 
85
  geometry.get("provider", GeometryProvider.DEPTH_ANYTHING),
86
  geometry.get("intrinsics"),
87
  surface_kind="wall",
 
88
  )
89
 
90
  plane = {
 
98
  "floorTransform": None,
99
  "surfaceTransform": None,
100
  "surfaceType": SurfaceType.WALL,
101
+ "surfaceWidthMeters": max(0.5, 2.4 * (x2 - x1) / max(y2 - y1, 1.0)),
102
+ "surfaceHeightMeters": 2.4,
 
 
103
  "metersPerUnit": None,
104
  "cameraIntrinsics": None,
105
  "camera": {"focalLength": float(max(h, w) * 0.95), "horizonY": y1, "confidence": 0.45},
visualizer.gpu.toml CHANGED
@@ -17,7 +17,7 @@ enable_depth_estimation = true
17
  enable_moge_geometry = true
18
  enable_plane_fit = true
19
  enable_multi_plane_surfaces = true
20
- enable_wall_segments = true
21
  enable_intrinsic_shading = false
22
  enable_shading_transfer = false
23
  enable_fast_shadow_transfer = true
@@ -34,7 +34,7 @@ data_dir = "data"
34
 
35
  [surface_mapping]
36
  ransac_distance_threshold = 0.04
37
- max_planes = 5
38
  normal_angle_threshold_degrees = 35
39
  normal_smoothing_kernel = 5
40
  min_plane_pixels = 1500
 
17
  enable_moge_geometry = true
18
  enable_plane_fit = true
19
  enable_multi_plane_surfaces = true
20
+ enable_wall_segments = false
21
  enable_intrinsic_shading = false
22
  enable_shading_transfer = false
23
  enable_fast_shadow_transfer = true
 
34
 
35
  [surface_mapping]
36
  ransac_distance_threshold = 0.04
37
+ max_planes = 1
38
  normal_angle_threshold_degrees = 35
39
  normal_smoothing_kernel = 5
40
  min_plane_pixels = 1500
visualizer.hf.toml CHANGED
@@ -17,7 +17,7 @@ enable_depth_estimation = true
17
  enable_moge_geometry = true
18
  enable_plane_fit = true
19
  enable_multi_plane_surfaces = true
20
- enable_wall_segments = true
21
  enable_intrinsic_shading = false
22
  enable_shading_transfer = false
23
  enable_fast_shadow_transfer = true
@@ -31,7 +31,7 @@ data_dir = "data"
31
 
32
  [surface_mapping]
33
  ransac_distance_threshold = 0.04
34
- max_planes = 5
35
  normal_angle_threshold_degrees = 35
36
  normal_smoothing_kernel = 5
37
  min_plane_pixels = 1500
 
17
  enable_moge_geometry = true
18
  enable_plane_fit = true
19
  enable_multi_plane_surfaces = true
20
+ enable_wall_segments = false
21
  enable_intrinsic_shading = false
22
  enable_shading_transfer = false
23
  enable_fast_shadow_transfer = true
 
31
 
32
  [surface_mapping]
33
  ransac_distance_threshold = 0.04
34
+ max_planes = 1
35
  normal_angle_threshold_degrees = 35
36
  normal_smoothing_kernel = 5
37
  min_plane_pixels = 1500
visualizer.local.toml CHANGED
@@ -13,7 +13,7 @@ sam2_checkpoint = ""
13
  enable_depth_estimation = false
14
  enable_plane_fit = true
15
  enable_multi_plane_surfaces = true
16
- enable_wall_segments = true
17
  enable_intrinsic_shading = false
18
  enable_shading_transfer = false
19
  enable_fast_shadow_transfer = true
 
13
  enable_depth_estimation = false
14
  enable_plane_fit = true
15
  enable_multi_plane_surfaces = true
16
+ enable_wall_segments = false
17
  enable_intrinsic_shading = false
18
  enable_shading_transfer = false
19
  enable_fast_shadow_transfer = true