fixing left appenmd

This commit is contained in:
2ManyProjects 2026-01-10 02:07:21 -06:00
parent 56d31edf8e
commit d128808a07

View file

@ -198,50 +198,58 @@ class StitchingScanner:
return result return result
else: # append_left - place at x_offset, NO width expansion else: # append_left - place at x_offset position
# x_offset is where the LEFT edge of the strip should go # x_offset represents where camera's LEFT edge is in mosaic coordinates
# For LEFT scanning, we pass abs(current_x) as x_offset
# The strip covers content from x_offset leftward
if x_offset is None: if x_offset is None:
x_offset = 0 x_offset = 0
# Clamp x_offset to valid range
x_offset = 0 - min(x_offset, w_base - blend_w)
self.log(f"=== _blend_horizontal_at_y (append_left) ===") self.log(f"=== _blend_horizontal_at_y (append_left) ===")
self.log(f" base: {w_base}x{h_base}, strip: {w_strip}x{h_strip}") self.log(f" base: {w_base}x{h_base}, strip: {w_strip}x{h_strip}")
self.log(f" x_offset: {x_offset}, y_offset: {y_offset}, blend_w: {blend_w}") self.log(f" x_offset (camera left edge): {x_offset}, y_offset: {y_offset}, blend_w: {blend_w}")
# Result is same size as base (no expansion when going left) # Result is same size as base (no expansion when going left)
result = base.copy() result = base.copy()
# Calculate placement bounds # Strip's RIGHT edge should align with camera's current left edge (x_offset)
strip_x_start = x_offset # Strip content goes from (x_offset - w_strip + blend_w) to x_offset
strip_x_end = min(x_offset + w_strip, w_base) strip_x_end = min(x_offset + blend_w, w_base) # Right edge with blend zone
strip_cols_to_copy = strip_x_end - strip_x_start strip_x_start = max(0, strip_x_end - w_strip)
actual_strip_width = strip_x_end - strip_x_start
self.log(f" Placing strip at X={strip_x_start}:{strip_x_end}, Y={y_offset}:{y_offset + h_strip}") self.log(f" Placing strip at X={strip_x_start}:{strip_x_end}, Y={y_offset}:{y_offset + h_strip}")
self.log(f" Strip cols to copy: {strip_cols_to_copy}") self.log(f" Actual strip width: {actual_strip_width}")
# Step 1: Copy strip content (non-blend portion) at correct position if actual_strip_width <= blend_w:
# For LEFT scanning, blend is on the RIGHT side of the strip self.log(f" Strip too narrow, skipping")
non_blend_end = strip_cols_to_copy - blend_w return result
if non_blend_end > 0:
result[y_offset:y_offset + h_strip, strip_x_start:strip_x_start + non_blend_end] = strip[:, :non_blend_end]
self.log(f" Step 1: Placed non-blend at X={strip_x_start}:{strip_x_start + non_blend_end}")
# Step 2: Create blend on the RIGHT edge of strip (blending with existing content) # Step 1: Copy non-blend portion of strip
# Strip's left portion (non-blend) goes at strip_x_start
non_blend_width = actual_strip_width - blend_w
if non_blend_width > 0:
# Take from LEFT side of strip (new content)
result[y_offset:y_offset + h_strip, strip_x_start:strip_x_start + non_blend_width] = strip[:, :non_blend_width]
self.log(f" Step 1: Placed {non_blend_width}px non-blend at X={strip_x_start}:{strip_x_start + non_blend_width}")
# Step 2: Blend zone at the RIGHT edge of where we're placing
blend_x_start = strip_x_end - blend_w blend_x_start = strip_x_end - blend_w
blend_x_end = strip_x_end blend_x_end = strip_x_end
if blend_w > 0 and blend_x_start >= strip_x_start: if blend_w > 0 and blend_x_start >= strip_x_start:
# Alpha: 1 at left (new content) -> 0 at right (existing content)
alpha = np.linspace(1, 0, blend_w, dtype=np.float32)[np.newaxis, :, np.newaxis] alpha = np.linspace(1, 0, blend_w, dtype=np.float32)[np.newaxis, :, np.newaxis]
strip_overlap = strip[:, -blend_w:].astype(np.float32) strip_overlap = strip[:, non_blend_width:non_blend_width + blend_w].astype(np.float32)
base_overlap = base[y_offset:y_offset + h_strip, blend_x_start:blend_x_end].astype(np.float32) base_overlap = base[y_offset:y_offset + h_strip, blend_x_start:blend_x_end].astype(np.float32)
blended = (strip_overlap * alpha + base_overlap * (1 - alpha)).astype(np.uint8) blended = (strip_overlap * alpha + base_overlap * (1 - alpha)).astype(np.uint8)
result[y_offset:y_offset + h_strip, blend_x_start:blend_x_end] = blended result[y_offset:y_offset + h_strip, blend_x_start:blend_x_end] = blended
self.log(f" Step 2: Blend zone at X={blend_x_start}:{blend_x_end}") self.log(f" Step 2: Blend zone at X={blend_x_start}:{blend_x_end}")
self.log(f" Final: Strip placed at X={strip_x_start}, Y={y_offset}, mosaic size unchanged: {w_base}x{h_base}") self.log(f" Final: Strip placed at X={strip_x_start}:{strip_x_end}, Y={y_offset}")
return result return result
def _blend_horizontal(self, base: np.ndarray, strip: np.ndarray, def _blend_horizontal(self, base: np.ndarray, strip: np.ndarray,