fix countdown frame fallback

This commit is contained in:
Your Name committed 2026-06-23 19:54:40 +08:00
1 parent 3ace80dcca
commit a2a899bb9f
5 files changed
+74 -25

No files matched your search

+5 -7
View File
@@ -334,8 +334,9 @@ def _parse_mmss_from_full_text(text: Any) -> Tuple[str, str]:
return mm, ss
# 2) 紧凑格式:1340后开奖 / 940后开奖
# 紧凑 3/4 位数字必须带开奖语境,否则商品编号如 G4939 会被误判成 49:39。
compact = re.search(
r"(?<!\d)(\d{3,4})(?=\D*(?:后开奖|开奖|后|$))",
r"(?<!\d)(\d{3,4})(?=\D*(?:后开奖|开奖|后))",
raw,
)
if compact:
@@ -547,7 +548,10 @@ def _apply_countdown_text_fallback(
mm_norm, ss_norm = _normalize_countdown_pair(countdown_mm_raw, countdown_ss_raw)
if mm_norm and ss_norm:
return countdown_mm_raw, countdown_ss_raw
allowed_sources = {"info_line", "countdown_full"}
for source_name, source_text in sources:
if source_name not in allowed_sources:
continue
mm_text, ss_text = _parse_mmss_from_full_text(source_text)
if not (mm_text and ss_text):
continue
@@ -1135,8 +1139,6 @@ def get_fudai_contain(analyser, renwu: int = 2) -> Tuple[str, str, int, int, flo
countdown_mm_raw,
countdown_ss_raw,
(
("content", fudai_content_raw),
("value", value_raw),
("info_line", info_line_raw),
("countdown_full", countdown_full_raw),
),
@@ -1265,8 +1267,6 @@ def get_fudai_contain(analyser, renwu: int = 2) -> Tuple[str, str, int, int, flo
countdown_mm_raw,
countdown_ss_raw,
(
("content", fudai_content_raw),
("value", value_raw),
("countdown_full", countdown_full_raw),
),
)
@@ -1543,8 +1543,6 @@ def get_fudai_contain(analyser, renwu: int = 2) -> Tuple[str, str, int, int, flo
countdown_mm_raw,
countdown_ss_raw,
(
("content", fudai_content_raw),
("value", value_raw),
("countdown_full", countdown_full_raw_fb),
),
)
@@ -64,17 +64,25 @@ def cut_detail_regions(
if not countdown_enabled:
return countdown_box
# 2. 倒计时区域分割(与候选切图保持一致,避免分钟框吃到前缀噪声)
# 2. 倒计时区域分割(v2 右侧 chip 左上角带 time:on 调试标签,需避开标签再切数字)
x1, y1, x2, y2 = countdown_box
w = max(1, int(x2 - x1))
h = max(1, int(y2 - y1))
# 纵向只取倒计时 chip 的数字行,避免把上方黑底或下方商品标题混入分钟/秒 OCR。
digit_y1 = min(y2 - 2, y1 + max(1, int(h * 0.34)))
digit_y2 = min(y2, max(digit_y1 + 2, y1 + max(2, int(h * 0.92))))
mm_x1 = x1
mm_x2 = min(x2, x1 + max(1, int(w * 0.26)))
ss_x1 = min(x2 - 1, x1 + max(1, int(w * 0.38)))
ss_x2 = min(x2, max(ss_x1 + 1, x1 + max(2, int(w * 0.64))))
if x1 >= 700:
digit_y1 = min(y2 - 2, y1 + max(1, int(h * 0.44)))
digit_y2 = y2
mm_x1 = min(x2 - 1, x1 + max(1, int(w * 0.12)))
mm_x2 = min(x2, max(mm_x1 + 1, x1 + max(2, int(w * 0.36))))
ss_x1 = min(x2 - 1, x1 + max(1, int(w * 0.42)))
ss_x2 = min(x2, max(ss_x1 + 1, x1 + max(2, int(w * 0.68))))
else:
# 旧布局不带左上调试标签,保留历史切法。
digit_y1 = min(y2 - 2, y1 + max(1, int(h * 0.34)))
digit_y2 = min(y2, max(digit_y1 + 2, y1 + max(2, int(h * 0.92))))
mm_x1 = x1
mm_x2 = min(x2, x1 + max(1, int(w * 0.26)))
ss_x1 = min(x2 - 1, x1 + max(1, int(w * 0.38)))
ss_x2 = min(x2, max(ss_x1 + 1, x1 + max(2, int(w * 0.64))))
analyser.cut_pic(
mm_x1,
@@ -1,8 +1,10 @@
from __future__ import annotations
from types import SimpleNamespace
from unittest.mock import MagicMock
from douyin.fudai.douyin_fudai_contain_impl import (
_apply_countdown_text_fallback,
_build_countdown_candidate_boxes,
_parse_mmss_from_full_text,
_select_countdown_from_candidates,
@@ -194,3 +196,37 @@ def test_parse_mmss_from_full_text_ignores_non_countdown_text():
mm, ss = _parse_mmss_from_full_text("直播间,否则会失去抽奖机会")
assert mm == ""
assert ss == ""
def test_parse_mmss_from_full_text_ignores_product_model_digits_without_countdown_hint():
mm, ss = _parse_mmss_from_full_text("G4939-敦煌飞天帝王黄茶叶罐")
assert mm == ""
assert ss == ""
def test_countdown_text_fallback_ignores_content_product_digits_without_countdown_hint():
analyser = SimpleNamespace(fudai_detail_verbose_logs=False)
mm, ss = _apply_countdown_text_fallback(
analyser,
"",
"",
(("content", "G4939-敦煌飞天帝王黄茶叶罐"),),
)
assert mm == ""
assert ss == ""
def test_countdown_text_fallback_does_not_use_content_even_with_countdown_text():
analyser = SimpleNamespace(fudai_detail_verbose_logs=False)
mm, ss = _apply_countdown_text_fallback(
analyser,
"",
"",
(("content", "免费购129人已参与00 : 00后开奖"),),
)
assert mm == ""
assert ss == ""
+15 -8
View File
@@ -96,7 +96,7 @@ class TestCutDetailRegions:
assert ss_call.args[0] == ss_x1
assert ss_call.args[2] == ss_x2
def test_profile_countdown_vertical_crop_is_narrower_and_higher(self):
def test_profile_countdown_vertical_crop_skips_left_label_for_v2_chip(self):
a = _mk_analyser()
profile = {"countdown_full": (760, 1328, 1038, 1398)}
@@ -104,12 +104,10 @@ class TestCutDetailRegions:
mm_call = a.cut_pic.call_args_list[1]
ss_call = a.cut_pic.call_args_list[2]
assert mm_call.args[1] == 1351
assert mm_call.args[3] == 1392
assert ss_call.args[1] == 1351
assert ss_call.args[3] == 1392
assert mm_call.args[:4] == (793, 1358, 860, 1398)
assert ss_call.args[:4] == (876, 1358, 949, 1398)
def test_v2_two_task_tall_profile_uses_lower_digit_band(self):
def test_v2_two_task_tall_profile_skips_left_label_and_uses_lower_digit_band(self):
a = _mk_analyser()
profile = {"countdown_full": (760, 1265, 1040, 1398)}
@@ -117,8 +115,12 @@ class TestCutDetailRegions:
mm_call = a.cut_pic.call_args_list[1]
ss_call = a.cut_pic.call_args_list[2]
assert mm_call.args[1] >= 1310
assert mm_call.args[3] >= 1385
assert mm_call.args[0] == 793
assert mm_call.args[2] == 860
assert ss_call.args[0] == 877
assert ss_call.args[2] == 950
assert mm_call.args[1] >= 1323
assert mm_call.args[3] == 1398
assert ss_call.args[1] == mm_call.args[1]
assert ss_call.args[3] == mm_call.args[3]
@@ -151,6 +153,11 @@ class TestCutDetailRegions:
result = cut_detail_regions(a, renwu=1, profile=profile)
assert result == (730, 1338, 1038, 1418)
mm_call = a.cut_pic.call_args_list[1]
ss_call = a.cut_pic.call_args_list[2]
assert mm_call.args[:4] == (766, 1373, 840, 1418)
assert ss_call.args[:4] == (859, 1373, 939, 1418)
def test_renwu_3_uses_correct_box(self):
a = _mk_analyser()
from douyin.fudai.core.coords import COUNTDOWN_1010_1130
+2 -2
View File
@@ -385,8 +385,8 @@ def test_countdown_text_fallback_uses_existing_ocr_without_extra_ocr():
"",
"",
(
("content", "免费购129人已参与00 : 00后开奖"),
("value", ""),
("info_line", "免费购129人已参与00 : 00后开奖"),
("countdown_full", ""),
),
)