fix: 修复ROI切片y_offset丢失导致地址拼接失败的问题

resize步骤未传递y_offset,导致OCR worker无法还原切片坐标,
跨切片的地址行(如"楼3号")无法与前一行正确拼接。
同时重写extract_with_layout为锚点算法(邮编/电话锚点+单栏/多栏自动切换),
支持单位名含地址关键字、电话同行等场景。

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
let5sne.win10
2026-02-24 23:38:33 +08:00
parent 6ce4b7b363
commit 8f6a4fbc68
4 changed files with 172 additions and 47 deletions

View File

@@ -540,6 +540,9 @@ class MainWindow(QMainWindow):
if job_id != self._ocr_job_id:
return
logger.info("OCR job=%s 原始文本: %s", job_id, texts)
logger.info("OCR job=%s 解析结果: %s", job_id, record)
self.records.append(record)
self.update_table()
cost = ""
@@ -996,7 +999,7 @@ class MainWindow(QMainWindow):
split_count = min(split_count, 4)
if split_count <= 1 or roi_box.shape[0] < 120:
roi_inputs.append({"img": roi_box, "source": "main"})
roi_inputs.append({"img": roi_box, "source": "main", "y_offset": 0})
else:
h_box = roi_box.shape[0]
step = h_box / float(split_count)
@@ -1012,7 +1015,7 @@ class MainWindow(QMainWindow):
)
part = roi_box[sy:ey, :]
if part is not None and part.size > 0:
roi_inputs.append({"img": part, "source": "main"})
roi_inputs.append({"img": part, "source": "main", "y_offset": sy})
except Exception:
pass
@@ -1043,13 +1046,15 @@ class MainWindow(QMainWindow):
for item in roi_inputs:
img = item.get("img")
source = item.get("source", "main")
y_off = item.get("y_offset", 0)
scale = 1.0
try:
if img is not None and img.shape[1] > max_w:
scale = max_w / img.shape[1]
img = cv2.resize(img, (int(img.shape[1] * scale), int(img.shape[0] * scale)))
except Exception:
pass
resized_inputs.append({"img": img, "source": source})
resized_inputs.append({"img": img, "source": source, "y_offset": int(y_off * scale)})
logger.info(
"UI 触发识别frame=%s, rois=%s, frame_age=%.3fs",