Codex staging deploy commited on
Commit
2688d45
·
1 Parent(s): 6311a9e

Preview feature/realistic-floor-rendering at 425218d

Browse files
Files changed (1) hide show
  1. app.py +50 -9
app.py CHANGED
@@ -3295,7 +3295,7 @@ def validate_wall_metric_geometry(geometry: dict) -> bool:
3295
  return True
3296
 
3297
 
3298
- def wall_surface_components(seg_map: np.ndarray, min_area: int):
3299
  """Create clean, independently renderable wall regions.
3300
 
3301
  Semantic wall predictions often bridge across corners and openings. Removing
@@ -3315,14 +3315,55 @@ def wall_surface_components(seg_map: np.ndarray, min_area: int):
3315
  wall = cv2.morphologyEx(wall, cv2.MORPH_OPEN, kernel)
3316
  wall[protected > 0] = 0
3317
 
3318
- count, labels, stats, _ = cv2.connectedComponentsWithStats(wall, connectivity=8)
3319
  components = []
3320
- for component_id in range(1, count):
3321
- area = int(stats[component_id, cv2.CC_STAT_AREA])
3322
- if area < min_area:
3323
- continue
3324
- component = (labels == component_id).astype(np.uint8)
3325
- components.append((area, component))
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
3326
  components.sort(key=lambda item: item[0], reverse=True)
3327
  return components, protected
3328
 
@@ -4225,7 +4266,7 @@ def build_segmentation_bundle(contents: bytes, debug: PipelineDebugCapture | Non
4225
 
4226
  wall_mask = np.isin(seg_map, class_ids({"wall"})).astype(np.uint8)
4227
  wall_components, wall_protected_mask = (
4228
- wall_surface_components(seg_map, min_floor_area)
4229
  if ENABLE_WALL_SEGMENTS else ([], np.zeros_like(wall_mask))
4230
  )
4231
 
 
3295
  return True
3296
 
3297
 
3298
+ def wall_surface_components(seg_map: np.ndarray, min_area: int, geometry: dict | None = None):
3299
  """Create clean, independently renderable wall regions.
3300
 
3301
  Semantic wall predictions often bridge across corners and openings. Removing
 
3315
  wall = cv2.morphologyEx(wall, cv2.MORPH_OPEN, kernel)
3316
  wall[protected > 0] = 0
3317
 
 
3318
  components = []
3319
+ if geometry is not None:
3320
+ maps = geometry_point_maps(wall, geometry)
3321
+ if maps is not None:
3322
+ valid = maps["validMask"] & (wall > 0)
3323
+ ys, xs = np.where(valid)
3324
+ if len(xs) >= SURFACE_MIN_PLANE_PIXELS:
3325
+ points = maps["points"][ys, xs].astype(np.float32)
3326
+ normals = maps["normals"][ys, xs].astype(np.float32)
3327
+ finite = np.isfinite(points).all(axis=1) & np.isfinite(normals).all(axis=1)
3328
+ points, normals, ys, xs = points[finite], normals[finite], ys[finite], xs[finite]
3329
+ if len(points) >= SURFACE_MIN_PLANE_PIXELS:
3330
+ normals_reliable = np.linalg.norm(normals, axis=1) > 1e-4
3331
+ if normals_reliable.sum() >= SURFACE_MIN_PLANE_PIXELS:
3332
+ points = points[normals_reliable]
3333
+ normals = normalize_vectors(normals[normals_reliable])
3334
+ ys, xs = ys[normals_reliable], xs[normals_reliable]
3335
+ planes = fit_multi_surface_planes(points, normals, True)
3336
+ wall_planes = [
3337
+ plane for plane in planes
3338
+ if abs(float(plane["normal"][1])) <= 0.45
3339
+ ]
3340
+ if wall_planes:
3341
+ assignment = assign_points_to_surface_planes(
3342
+ points, normals, wall_planes, True
3343
+ )
3344
+ for plane_index in range(len(wall_planes)):
3345
+ selected = assignment == plane_index
3346
+ if int(selected.sum()) < min_area:
3347
+ continue
3348
+ plane_mask = np.zeros_like(wall)
3349
+ plane_mask[ys[selected], xs[selected]] = 1
3350
+ count, labels, stats, _ = cv2.connectedComponentsWithStats(
3351
+ plane_mask, connectivity=8
3352
+ )
3353
+ for component_id in range(1, count):
3354
+ area = int(stats[component_id, cv2.CC_STAT_AREA])
3355
+ if area >= min_area:
3356
+ components.append((area, (labels == component_id).astype(np.uint8)))
3357
+
3358
+ # Geometry can be unavailable or too noisy. In that case retain the safe
3359
+ # semantic connected-component fallback instead of emitting no walls.
3360
+ if not components:
3361
+ count, labels, stats, _ = cv2.connectedComponentsWithStats(wall, connectivity=8)
3362
+ for component_id in range(1, count):
3363
+ area = int(stats[component_id, cv2.CC_STAT_AREA])
3364
+ if area < min_area:
3365
+ continue
3366
+ components.append((area, (labels == component_id).astype(np.uint8)))
3367
  components.sort(key=lambda item: item[0], reverse=True)
3368
  return components, protected
3369
 
 
4266
 
4267
  wall_mask = np.isin(seg_map, class_ids({"wall"})).astype(np.uint8)
4268
  wall_components, wall_protected_mask = (
4269
+ wall_surface_components(seg_map, min_floor_area, geometry)
4270
  if ENABLE_WALL_SEGMENTS else ([], np.zeros_like(wall_mask))
4271
  )
4272