feat: 拼接偵測加入左右排除邊距,box 預設排除右側多出的一欄

錯位模組畫面有 6x3 共 18 格,原本只能靠過渡門檻碰巧湊到 15 格且選錯格。stitcher.exclude_x 只篩選格子,box 設定為 [0, 240],可依感測器改寫;合成畫面測試與實機連續開啟 6 次全數成功。

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
ykcheungab
2026-10-22 20:03:44 +08:00
parent f5738375fd
commit ad7b0d3e26
5 changed files with 71 additions and 1 deletions
+3
View File
@@ -44,6 +44,8 @@ class Stitcher:
self.box_size = config_stitcher["box_size"]
# Physical tile count for box detection (often 15); grid n is the active stitch layout.
self.n_boxes_target = int(config_stitcher.get("n_boxes_target", 15))
# (left, right) raw-frame pixels whose tiles are not counted (extra column).
self.exclude_x = tuple(int(v) for v in config_stitcher.get("exclude_x", (0, 0)))
self._blend_coef_cache = {}
self._feature_stitch_cache = {
@@ -246,6 +248,7 @@ class Stitcher:
ncol=self.ncol,
show=show,
n_boxes_target=self.n_boxes_target,
exclude_x=self.exclude_x,
)
self.boxes = boxes
# Detection target is physical unit count; active stitch grid is nrow*ncol via index.
+15 -1
View File
@@ -72,8 +72,14 @@ def detect_nonblack_regions(
show: bool = False,
row_tol: float = 0.4,
save_preview_path: str = "./config/compound_eye.png",
exclude_x: Sequence[int] = (0, 0),
) -> tuple[int, list[tuple[int, int, int, int]]]:
"""Detect tile boxes; returns ``(n_boxes, boxes as x0,y0,x1,y1)``."""
"""Detect tile boxes; returns ``(n_boxes, boxes as x0,y0,x1,y1)``.
``exclude_x`` is ``(left, right)`` in raw-frame pixels: a region whose centre
lies that close to the left or right edge is ignored. A misaligned module can
show an extra column of tiles; this keeps it out of the count.
"""
if img is None:
raise ValueError("Input image is None.")
@@ -81,6 +87,7 @@ def detect_nonblack_regions(
n_boxes = 0
bk_thresh = 0
boxes: list[tuple[int, int, int, int]] = []
exclude_left, exclude_right = (int(value) for value in exclude_x)
hsv = cv2.cvtColor(img, cv2.COLOR_BGR2HSV)
v = hsv[:, :, 2]
@@ -110,6 +117,11 @@ def detect_nonblack_regions(
max_area_frac=max_area_frac,
max_aspect_ratio=max_aspect_ratio,
)
boxes = [
box
for box in boxes
if exclude_left <= box[0] + box[2] / 2 <= w - exclude_right
]
n_boxes = len(boxes)
bk_thresh += bk_thresh_step
@@ -193,6 +205,7 @@ def find_stitch_boxes(
ncol: int,
show: bool = False,
n_boxes_target: int | None = None,
exclude_x: Sequence[int] = (0, 0),
):
"""Run bloom correction + detection; return ``(n_boxes, boxes, grid_ok)``.
@@ -210,6 +223,7 @@ def find_stitch_boxes(
n_boxes_target=target,
show=show,
row_tol=row_tol,
exclude_x=exclude_x,
)
grid_ok = n_boxes == target
return n_boxes, boxes, grid_ok