改了设置

This commit is contained in:
i
2026-04-22 10:45:09 +08:00
parent e06297f06b
commit 2996ba96e7
2 changed files with 102 additions and 37 deletions
+9 -8
View File
@@ -225,7 +225,7 @@ def _undistort_points(u, v, intr, dist):
return x_u, y_u
def software_d2c(depth_img, params, splat=True):
def software_d2c(depth_img, params, splat_radius=1):
"""
Transform a uint16 depth image (depth camera space) to an aligned uint16
depth image in color camera space.
@@ -301,12 +301,12 @@ def software_d2c(depth_img, params, splat=True):
aligned = np.zeros((color_h, color_w), dtype=np.uint16)
if splat:
# Splat each depth pixel to a 3×3 neighbourhood to fill sub-pixel gaps
if splat_radius > 0:
# Splat each depth pixel to an N×N neighbourhood to fill sub-pixel gaps
# that arise from forward projection. Far→near order is preserved so
# the nearest surface always wins when splats overlap.
for dv in range(-1, 2):
for du in range(-1, 2):
for dv in range(-splat_radius, splat_radius + 1):
for du in range(-splat_radius, splat_radius + 1):
us = np.clip(u_vals + du, 0, color_w - 1)
vs = np.clip(v_vals + dv, 0, color_h - 1)
aligned[vs, us] = z_vals
@@ -333,7 +333,7 @@ def depth_to_colormap(aligned, min_depth_mm=200, max_depth_mm=5000, depth_scale=
return colormap
def batch_convert(params, depth_dir_str, splat=True):
def batch_convert(params, depth_dir_str, splat_radius=1):
depth_dir = Path(depth_dir_str.strip().strip('"\''))
if not depth_dir.exists():
print(f" Directory not found: {depth_dir}")
@@ -361,7 +361,8 @@ def batch_convert(params, depth_dir_str, splat=True):
print(f" Files : {len(png_files)}")
print(f" Depth scale : {depth_scale:.6f} mm/unit")
print(f" Output size : {color_w}x{color_h} (color resolution)")
print(f" Splat (3×3) : {'on' if splat else 'off'}")
sz = 2 * splat_radius + 1
print(f" Splat : {f'{sz}×{sz}' if splat_radius > 0 else 'off'}")
print()
t0 = time.time()
@@ -382,7 +383,7 @@ def batch_convert(params, depth_dir_str, splat=True):
depth_img = depth_img[:, :, 0]
depth_img = depth_img.astype(np.uint16)
aligned = software_d2c(depth_img, params, splat=splat)
aligned = software_d2c(depth_img, params, splat_radius=splat_radius)
# Save aligned uint16 depth
cv2.imwrite(str(out_dir / fpath.name), aligned)