From 4d4f0ae666b719e12366c11f405f0c2163086ba7 Mon Sep 17 00:00:00 2001 From: butubb <1422726308@qq.com> Date: Fri, 4 Sep 2026 14:33:28 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20OCR=20=E6=96=87=E5=AD=97=E7=82=B9?= =?UTF-8?q?=E5=87=BB=E8=90=BD=E7=82=B9=E7=B2=BE=E5=BA=A6=E2=80=94=E2=80=94?= =?UTF-8?q?=E5=91=BD=E4=B8=AD=E6=96=87=E6=9C=AC=E5=9D=97=E8=BE=83=E9=95=BF?= =?UTF-8?q?=E6=97=B6=EF=BC=88=E4=B8=80=E8=A1=8C=E5=90=AB=E5=A4=9A=E6=AE=B5?= =?UTF-8?q?=E6=96=87=E5=AD=97=EF=BC=89=E6=8C=89=E5=85=B3=E9=94=AE=E8=AF=8D?= =?UTF-8?q?=E5=9C=A8=E6=96=87=E6=9C=AC=E4=B8=AD=E7=9A=84=E4=BD=8D=E7=BD=AE?= =?UTF-8?q?=E6=AF=94=E4=BE=8B=E4=BC=B0=E7=AE=97=20x=EF=BC=8C=E9=81=BF?= =?UTF-8?q?=E5=85=8D=E7=82=B9=E6=95=B4=E5=9D=97=E4=B8=AD=E5=BF=83=E5=81=8F?= =?UTF-8?q?=E7=A6=BB=E5=85=B3=E9=94=AE=E8=AF=8D=EF=BC=88tap=5Ftext=20?= =?UTF-8?q?=E4=B8=8E=E4=BB=BB=E5=8A=A1=20OCR=20=E6=9D=A1=E4=BB=B6=E5=85=B1?= =?UTF-8?q?=E7=94=A8=E5=8F=97=E7=9B=8A=EF=BC=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- core/ocr.py | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/core/ocr.py b/core/ocr.py index 6e43ec8..057ab6f 100644 --- a/core/ocr.py +++ b/core/ocr.py @@ -69,11 +69,22 @@ def recognize(image): def find_on_screen(image, keyword): """在截图上查找包含 keyword 的文字。 - 返回 (found, center_xy, matched_text);center_xy 为文字中心像素坐标(可点击), - 未命中返回 (False, None, "")。 + 返回 (found, center_xy, matched_text);center_xy 为**关键词**中心像素坐标 + (可点击),未命中返回 (False, None, "")。 + + OCR 一行常含多段文字(如 "医值得推荐#苏州济世璞真…展开"),若直接点整块 + 中心会偏离关键词很远。命中块文本较长时,按关键词在文本中的位置比例估算 x + (块内文字近似等宽),y 取块中心——中文场景估算偏差小,点击能落准。 """ for r in recognize(image): - if keyword in r["text"]: + text = r["text"] + if keyword in text: b = r["box"] - return True, ((b[0] + b[2]) // 2, (b[1] + b[3]) // 2), r["text"] + if len(text) <= 12: # 短文本:整块中心即关键词中心 + return True, ((b[0] + b[2]) // 2, (b[1] + b[3]) // 2), text + idx = text.find(keyword) + ratio = (idx + len(keyword) / 2) / len(text) + cx = b[0] + int((b[2] - b[0]) * ratio) + cy = (b[1] + b[3]) // 2 + return True, (cx, cy), text return False, None, ""