This commit is contained in:
HuangHai
2026-01-18 13:44:51 +08:00
parent bdbc6f46d1
commit 6688daa446
9 changed files with 61 additions and 35 deletions

View File

@@ -16,6 +16,7 @@ from Util.LlmUtil import get_llm_response
logger = setup_logger("TeLaiDian.FirstPageKit")
TEXT_TOP_RATIO = SAFE_EXCLUDE_RATIO * 0.8
NON_STATION_KEYWORDS = [
"地图",
@@ -116,21 +117,31 @@ async def run_ocr_rect(image_path, log_path=None):
status = "keep"
reasons = []
txt = text or ""
if prob < 0.3:
status = "drop"
reasons.append("prob<0.3")
if not text:
if not txt:
status = "drop"
reasons.append("empty_text")
if cy_norm < SAFE_EXCLUDE_RATIO:
has_station_kw = False
has_distance_kw = False
if txt:
if ("充电站" in txt) or ("超快充" in txt) or ("快充" in txt) or ("慢充" in txt):
has_station_kw = True
if ("km" in txt) or ("m" in txt):
has_distance_kw = True
if cy_norm < TEXT_TOP_RATIO and not (
(has_station_kw and len(txt) >= 4) or has_distance_kw
):
status = "drop"
reasons.append("top_safe_zone")
if cy_norm > (1 - BOTTOM_SAFE_EXCLUDE_RATIO):
status = "drop"
reasons.append("bottom_safe_zone")
if status == "keep" and text:
if status == "keep" and txt:
for kw in NON_STATION_KEYWORDS:
if kw and kw in text:
if kw and kw in txt:
status = "drop"
reasons.append("non_station_keyword")
break
@@ -325,10 +336,13 @@ async def run_ocr_rect(image_path, log_path=None):
prev_y2 = None
anchor_ratio = 0.15
for idx, st in enumerate(stations, start=1):
name = st.get("station_name")
py = st["anchor_py"]
if py < effective_top:
log_detail(f"锚点位于顶部保护区,丢弃: {st.get('station_name')} py={py}")
continue
anchor_norm = st.get("anchor_point_norm") or {}
try:
ay = float(anchor_norm.get("y", py / h))
except Exception:
ay = py / h
y1 = int(py - box_h * anchor_ratio)
y2 = y1 + box_h
if min_gap is not None:
@@ -343,9 +357,6 @@ async def run_ocr_rect(image_path, log_path=None):
if y2 > h:
y2 = h
y1 = y2 - box_h
if y1 < effective_top:
y1 = effective_top
y2 = y1 + box_h
if y2 > effective_bottom:
y2 = effective_bottom
y1 = y2 - box_h
@@ -355,15 +366,13 @@ async def run_ocr_rect(image_path, log_path=None):
y2 += shift
if y2 > effective_bottom:
if idx == len(stations):
min_h = int(box_h * 0.5)
new_y1 = prev_y2 + 1
new_y2 = effective_bottom
if new_y2 - new_y1 >= min_h:
y1 = new_y1
y2 = new_y2
else:
if new_y2 <= new_y1:
log_detail(f"底部空间不足,丢弃: {st.get('station_name')}")
continue
y1 = new_y1
y2 = new_y2
else:
log_detail(f"避免重叠无法放置,丢弃: {st.get('station_name')}")
continue
@@ -391,7 +400,7 @@ async def run_ocr_rect(image_path, log_path=None):
)
try:
draw_rectangles(image_path, rects, click_points)
draw_rectangles(image_path, rects, click_points, save_vl=False)
except Exception as e:
log_detail(f"绘制调试矩形失败: {e}")
@@ -416,8 +425,12 @@ async def run_ocr_rect(image_path, log_path=None):
async def run_batch_in_dir(image_dir, log_file=None):
img_files = []
for name in os.listdir(image_dir):
if name.lower().endswith(".jpg") or name.lower().endswith(".png"):
img_files.append(os.path.join(image_dir, name))
lower = name.lower()
if not (lower.endswith(".jpg") or lower.endswith(".png")):
continue
if "_flag" in lower or "_vl" in lower:
continue
img_files.append(os.path.join(image_dir, name))
img_files.sort()
if not img_files: