From d8553d4a84563e52c1ac5f45d3582f333f3f5f18 Mon Sep 17 00:00:00 2001 From: 2ManyProjects Date: Sat, 10 Jan 2026 02:41:24 -0600 Subject: [PATCH] abs x --- src/stitching_scanner.py | 50 +++++++++++++++++++++++----------------- 1 file changed, 29 insertions(+), 21 deletions(-) diff --git a/src/stitching_scanner.py b/src/stitching_scanner.py index 212f63f..fc2bfea 100644 --- a/src/stitching_scanner.py +++ b/src/stitching_scanner.py @@ -198,50 +198,58 @@ class StitchingScanner: return result - else: # append_left - place at x_offset, NO width expansion - # x_offset is where the LEFT edge of the strip should go + else: # append_left - place at x_offset position + # 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: 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" 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 = base.copy() - # Calculate placement bounds - strip_x_start = x_offset - strip_x_end = min(x_offset + w_strip, w_base) - strip_cols_to_copy = strip_x_end - strip_x_start + # Strip's RIGHT edge should align with camera's current left edge (x_offset) + # Strip content goes from (x_offset - w_strip + blend_w) to x_offset + strip_x_end = min(x_offset + blend_w, w_base) # Right edge with blend zone + 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" 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 - # For LEFT scanning, blend is on the RIGHT side of the strip - non_blend_end = strip_cols_to_copy - blend_w - 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}") + if actual_strip_width <= blend_w: + self.log(f" Strip too narrow, skipping") + return result - # 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_end = strip_x_end 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] - 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) 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 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 def _blend_horizontal(self, base: np.ndarray, strip: np.ndarray, @@ -423,7 +431,7 @@ class StitchingScanner: strip_end = min(w, append_width + BLEND_WIDTH) new_strip = frame[:, :strip_end] self.mosaic = self._blend_horizontal_at_y( - self.mosaic, new_strip, BLEND_WIDTH, append_right=False, x_offset=int(self.state.current_x), y_offset=y_offset) + self.mosaic, new_strip, BLEND_WIDTH, append_right=False, x_offset=int(abs(self.state.current_x)), y_offset=y_offset) self._displacement_since_append_x = fractional_remainder self._displacement_since_append_y = 0.0