fix fudai countdown full-line ocr

This commit is contained in:
Your Name committed 2026-06-23 23:32:20 +08:00
1 parent 008d7f82b3
commit 9062ee7204
6 files changed
+41 -387

No files matched your search

+6 -268
View File
@@ -201,17 +201,13 @@ def _should_schedule_task_list_ocr(analyser: Any, ocr_switches: Any) -> bool:
def _should_schedule_countdown_full_ocr(analyser: Any, ocr_switches: Any) -> bool:
"""Use split minute/second OCR by default; full-line OCR is an opt-in fallback."""
"""Use full-line countdown OCR as the only countdown source."""
try:
if not bool(getattr(ocr_switches, "countdown", False)):
return False
except Exception:
return False
return _get_bool_setting(
analyser,
"fudai_detail_countdown_full_ocr_in_critical_path_enabled",
False,
)
return True
def _should_schedule_info_line_ocr(analyser: Any, ocr_switches: Any) -> bool:
@@ -701,10 +697,6 @@ def get_fudai_contain(analyser, renwu: int = 2) -> Tuple[str, str, int, int, flo
ui_version = str(profile.get("version") or "v2_0")
ocr_switches = FudaiDetailOcrSwitches()
countdown_full_ocr_in_critical_path = _should_schedule_countdown_full_ocr(
analyser,
ocr_switches,
)
info_line_ocr_in_critical_path = _should_schedule_info_line_ocr(
analyser,
ocr_switches,
@@ -791,69 +783,6 @@ def get_fudai_contain(analyser, renwu: int = 2) -> Tuple[str, str, int, int, flo
)
except Exception:
pass
# 额外整行倒计时图:默认不进关键路径;需要专项兜底时显式开启。
try:
if countdown_full_ocr_in_critical_path:
analyser.cut_pic(*countdown_box, "", "福袋倒计时_整行", analyser.y_pianyi)
elif ocr_switches.countdown:
analyser._log_kv(
"性能",
"跳过倒计时整行OCR关键路径",
reason="countdown_full_ocr_not_in_critical_path",
enable_key="fudai_detail_countdown_full_ocr_in_critical_path_enabled",
)
except Exception:
pass
# 额外切割倒计时候选区域(用于并行多候选OCR,根治分钟框偏移)
countdown_candidate_meta: List[Dict[str, Any]] = []
try:
candidate_boxes = [tuple(countdown_box)] if ui_version == "v2_0" else _build_countdown_candidate_boxes(renwu)
for idx, box in enumerate(candidate_boxes):
is_primary = (tuple(box) == tuple(countdown_box))
if is_primary:
# 主候选沿用原始“福袋倒计时_分钟/秒”命名,兼容现有OCR与调试图像链路
mm_name = "福袋倒计时_分钟"
ss_name = "福袋倒计时_秒"
mm_key = "countdown_mm"
ss_key = "countdown_ss"
else:
mm_name = f"福袋倒计时_候选{idx}_分钟"
ss_name = f"福袋倒计时_候选{idx}_秒"
mm_key = f"countdown_mm_c{idx}"
ss_key = f"countdown_ss_c{idx}"
if ocr_switches.countdown:
_cut_countdown_candidate_regions(
analyser,
tuple(box),
mm_name,
ss_name,
save_debug_images=False,
)
countdown_candidate_meta.append(
{
"idx": idx,
"box": tuple(box),
"is_primary": is_primary,
"mm_name": mm_name,
"ss_name": ss_name,
"mm_result_key": mm_key,
"ss_result_key": ss_key,
}
)
except Exception:
countdown_candidate_meta = [
{
"idx": 0,
"box": tuple(countdown_box),
"is_primary": True,
"mm_name": "福袋倒计时_分钟",
"ss_name": "福袋倒计时_秒",
"mm_result_key": "countdown_mm",
"ss_result_key": "countdown_ss",
}
]
# 准备任务列表区域的截图(用于并行OCR)
try:
task_list_ocr_in_critical_path = _should_schedule_task_list_ocr(
@@ -975,8 +904,6 @@ def get_fudai_contain(analyser, renwu: int = 2) -> Tuple[str, str, int, int, flo
)
ocr_task_list = _ocr_runner.ocr_task_list
ocr_content = _ocr_runner.ocr_content
ocr_countdown_mm = _ocr_runner.ocr_countdown_mm
ocr_countdown_ss = _ocr_runner.ocr_countdown_ss
ocr_countdown_full = _ocr_runner.ocr_countdown_full
ocr_value = _ocr_runner.ocr_value
ocr_button = _ocr_runner.ocr_button
@@ -1000,10 +927,7 @@ def get_fudai_contain(analyser, renwu: int = 2) -> Tuple[str, str, int, int, flo
if _should_schedule_task_list_ocr(analyser, ocr_switches):
task_funcs["task_list"] = ocr_task_list
if ocr_switches.countdown:
task_funcs["countdown_mm"] = ocr_countdown_mm
task_funcs["countdown_ss"] = ocr_countdown_ss
if countdown_full_ocr_in_critical_path:
task_funcs["countdown_full"] = ocr_countdown_full
task_funcs["countdown_full"] = ocr_countdown_full
if ocr_switches.value:
task_funcs["value"] = ocr_value
if ocr_switches.button:
@@ -1029,35 +953,6 @@ def get_fudai_contain(analyser, renwu: int = 2) -> Tuple[str, str, int, int, flo
reason="info_line_ocr_not_in_critical_path",
enable_key="fudai_detail_info_line_ocr_in_critical_path_enabled",
)
# 并行补充倒计时额外候选(保持并行,不降级)
for meta in countdown_candidate_meta:
if meta.get("is_primary"):
continue
mm_name = str(meta.get("mm_name") or "")
ss_name = str(meta.get("ss_name") or "")
mm_key = str(meta.get("mm_result_key") or "")
ss_key = str(meta.get("ss_result_key") or "")
if not mm_name or not ss_name or not mm_key or not ss_key:
continue
if ocr_switches.countdown:
task_funcs[mm_key] = (
lambda name=mm_name: "".join(
ch
for ch in str(
analyser.operation.analyse_pic_digits(name, 0) or ""
)
if ch.isdigit()
)
)
task_funcs[ss_key] = (
lambda name=ss_name: "".join(
ch
for ch in str(
analyser.operation.analyse_pic_digits(name, 0) or ""
)
if ch.isdigit()
)
)
# 如果配置启用,避免把 content 任务加入并行队列,彻底不调度该OCR
if ocr_switches.content:
task_funcs["content"] = ocr_content
@@ -1069,7 +964,6 @@ def get_fudai_contain(analyser, renwu: int = 2) -> Tuple[str, str, int, int, flo
# 收集结果并记录耗时
results, durations = run_parallel_tasks(task_funcs, executor)
extra_countdown_results: Dict[str, Any] = {}
for name, res in results.items():
if name == "task_list":
task_list_raw = res
@@ -1091,20 +985,10 @@ def get_fudai_contain(analyser, renwu: int = 2) -> Tuple[str, str, int, int, flo
info_line_raw = res
elif name == "live_room_title":
live_room_title_raw, live_room_title_text_raw = res
elif name.startswith("countdown_mm_c") or name.startswith("countdown_ss_c"):
extra_countdown_results[name] = res
try:
if not ocr_switches.countdown:
raise RuntimeError("countdown_ocr_disabled")
countdown_mm_raw, countdown_ss_raw, picked = _select_countdown_from_candidates(
analyser,
countdown_candidate_meta,
countdown_mm_raw,
countdown_ss_raw,
extra_countdown_results,
room_title_hint=str(live_room_title_text_raw or live_room_title_raw or ""),
)
mm_full, ss_full = _parse_mmss_from_full_text(countdown_full_raw)
if mm_full and ss_full:
countdown_mm_raw, countdown_ss_raw = mm_full, ss_full
@@ -1112,7 +996,7 @@ def get_fudai_contain(analyser, renwu: int = 2) -> Tuple[str, str, int, int, flo
try:
analyser._log_kv(
"倒计时",
"倒计时整行优先命中,覆盖分割候选结果",
"倒计时整行命中",
full_text=str(countdown_full_raw or "")[:80],
mm=mm_full,
ss=ss_full,
@@ -1134,35 +1018,6 @@ def get_fudai_contain(analyser, renwu: int = 2) -> Tuple[str, str, int, int, flo
)
except Exception:
pass
countdown_mm_raw, countdown_ss_raw = _apply_countdown_text_fallback(
analyser,
countdown_mm_raw,
countdown_ss_raw,
(
("info_line", info_line_raw),
("countdown_full", countdown_full_raw),
),
)
if picked:
picked_idx = int(picked.get("idx", -1))
if _detail_verbose_logs(analyser):
analyser._log_kv(
"倒计时",
(
"倒计时候选选择结果"
f" idx={picked_idx}"
f" mm={str(picked.get('mm') or '')}"
f" ss={str(picked.get('ss') or '')}"
f" valid={bool(picked.get('valid'))}"
),
chosen_idx=picked_idx,
chosen_is_primary=bool(picked.get("is_primary")),
chosen_mm=str(picked.get("mm") or ""),
chosen_ss=str(picked.get("ss") or ""),
chosen_score=int(picked.get("score", 0) or 0),
chosen_valid=bool(picked.get("valid")),
candidates=len(countdown_candidate_meta),
)
# 回写连续性状态:供下一次候选评分使用(同直播间递减约束)。
try:
room_for_state = str(live_room_title_text_raw or live_room_title_raw or "").strip()
@@ -1225,8 +1080,6 @@ def get_fudai_contain(analyser, renwu: int = 2) -> Tuple[str, str, int, int, flo
allowed_heavy_fields: set[str] = set()
if ocr_switches.content:
allowed_heavy_fields.add("content")
if ocr_switches.countdown:
allowed_heavy_fields.update({"countdown_mm", "countdown_ss"})
if ocr_switches.value:
allowed_heavy_fields.add("value")
if ocr_switches.task:
@@ -1237,59 +1090,19 @@ def get_fudai_contain(analyser, renwu: int = 2) -> Tuple[str, str, int, int, flo
if heavy_fields:
heavy_res = run_heavy_ocr(analyser, heavy_fields)
picked_heavy = None
def _prefer(new_val: Any, old_val: Any):
return new_val if not is_blank_text(new_val) else old_val
task_list_raw = _prefer(heavy_res.get("task_list"), task_list_raw)
fudai_content_raw = _prefer(heavy_res.get("content"), fudai_content_raw)
countdown_mm_raw = _prefer(heavy_res.get("countdown_mm"), countdown_mm_raw)
countdown_ss_raw = _prefer(heavy_res.get("countdown_ss"), countdown_ss_raw)
value_raw = _prefer(heavy_res.get("value"), value_raw)
button_text_raw = _prefer(heavy_res.get("button"), button_text_raw)
try:
if ("countdown_mm" in heavy_fields) or ("countdown_ss" in heavy_fields):
countdown_mm_raw, countdown_ss_raw, picked_heavy = _select_countdown_from_candidates(
analyser,
countdown_candidate_meta,
countdown_mm_raw,
countdown_ss_raw,
extra_countdown_results,
room_title_hint=str(live_room_title_text_raw or live_room_title_raw or ""),
)
mm_full_h, ss_full_h = _parse_mmss_from_full_text(countdown_full_raw)
if mm_full_h and ss_full_h:
countdown_mm_raw, countdown_ss_raw = mm_full_h, ss_full_h
countdown_mm_raw, countdown_ss_raw = _apply_countdown_text_fallback(
analyser,
countdown_mm_raw,
countdown_ss_raw,
(
("countdown_full", countdown_full_raw),
),
)
if picked_heavy:
picked_heavy_idx = int(picked_heavy.get("idx", -1))
if _detail_verbose_logs(analyser):
analyser._log_kv(
"倒计时",
(
"重OCR后倒计时候选复选结果"
f" idx={picked_heavy_idx}"
f" mm={str(picked_heavy.get('mm') or '')}"
f" ss={str(picked_heavy.get('ss') or '')}"
f" valid={bool(picked_heavy.get('valid'))}"
),
chosen_idx=picked_heavy_idx,
chosen_is_primary=bool(picked_heavy.get("is_primary")),
chosen_mm=str(picked_heavy.get("mm") or ""),
chosen_ss=str(picked_heavy.get("ss") or ""),
chosen_score=int(picked_heavy.get("score", 0) or 0),
chosen_valid=bool(picked_heavy.get("valid")),
candidates=len(countdown_candidate_meta),
)
except Exception:
pass
@@ -1432,8 +1245,6 @@ def get_fudai_contain(analyser, renwu: int = 2) -> Tuple[str, str, int, int, flo
)
ocr_task_list_fallback = _fb_runner.ocr_task_list
ocr_content_fallback = _fb_runner.ocr_content
ocr_countdown_mm_fallback = _fb_runner.ocr_countdown_mm
ocr_countdown_ss_fallback = _fb_runner.ocr_countdown_ss
ocr_countdown_full_fallback = _fb_runner.ocr_countdown_full
ocr_value_fallback = _fb_runner.ocr_value
ocr_button_fallback = _fb_runner.ocr_button
@@ -1451,10 +1262,7 @@ def get_fudai_contain(analyser, renwu: int = 2) -> Tuple[str, str, int, int, flo
if _should_schedule_task_list_ocr(analyser, ocr_switches):
task_funcs["task_list"] = ocr_task_list_fallback
if ocr_switches.countdown:
task_funcs["countdown_mm"] = ocr_countdown_mm_fallback
task_funcs["countdown_ss"] = ocr_countdown_ss_fallback
if countdown_full_ocr_in_critical_path:
task_funcs["countdown_full"] = ocr_countdown_full_fallback
task_funcs["countdown_full"] = ocr_countdown_full_fallback
if ocr_switches.value:
task_funcs["value"] = ocr_value_fallback
if ocr_switches.button:
@@ -1463,35 +1271,6 @@ def get_fudai_contain(analyser, renwu: int = 2) -> Tuple[str, str, int, int, flo
task_funcs["participants"] = (
lambda: analyser.operation.analyse_pic_word("福袋参与人数", 0)
)
# 备用并行中也加入倒计时额外候选
for meta in countdown_candidate_meta:
if meta.get("is_primary"):
continue
mm_name = str(meta.get("mm_name") or "")
ss_name = str(meta.get("ss_name") or "")
mm_key = str(meta.get("mm_result_key") or "")
ss_key = str(meta.get("ss_result_key") or "")
if not mm_name or not ss_name or not mm_key or not ss_key:
continue
if ocr_switches.countdown:
task_funcs[mm_key] = (
lambda name=mm_name: "".join(
ch
for ch in str(
analyser.operation.analyse_pic_digits(name, 0) or ""
)
if ch.isdigit()
)
)
task_funcs[ss_key] = (
lambda name=ss_name: "".join(
ch
for ch in str(
analyser.operation.analyse_pic_digits(name, 0) or ""
)
if ch.isdigit()
)
)
# 如果配置允许,则加入备用 content OCR,否则不调度
if ocr_switches.content:
task_funcs["content"] = ocr_content_fallback
@@ -1501,7 +1280,6 @@ def get_fudai_contain(analyser, renwu: int = 2) -> Tuple[str, str, int, int, flo
participants_raw = None
countdown_full_raw_fb = None
results, durations = run_parallel_tasks(task_funcs, executor)
extra_countdown_results_fb: Dict[str, Any] = {}
for name, res in results.items():
if name == "task_list":
task_list_raw = res
@@ -1519,53 +1297,13 @@ def get_fudai_contain(analyser, renwu: int = 2) -> Tuple[str, str, int, int, flo
button_text_raw = res
elif name == "participants":
participants_raw = res
elif name.startswith("countdown_mm_c") or name.startswith("countdown_ss_c"):
extra_countdown_results_fb[name] = res
try:
if not ocr_switches.countdown:
raise RuntimeError("countdown_ocr_disabled")
countdown_mm_raw, countdown_ss_raw, picked_fb = _select_countdown_from_candidates(
analyser,
countdown_candidate_meta,
countdown_mm_raw,
countdown_ss_raw,
extra_countdown_results_fb,
room_title_hint=str(
getattr(analyser, "current_room_title_raw", "") or ""
),
)
mm_fb, ss_fb = _parse_mmss_from_full_text(countdown_full_raw_fb)
if countdown_full_ocr_in_critical_path and mm_fb and ss_fb:
if mm_fb and ss_fb:
countdown_mm_raw, countdown_ss_raw = mm_fb, ss_fb
countdown_mm_raw, countdown_ss_raw = _apply_countdown_text_fallback(
analyser,
countdown_mm_raw,
countdown_ss_raw,
(
("countdown_full", countdown_full_raw_fb),
),
)
if picked_fb:
picked_fb_idx = int(picked_fb.get("idx", -1))
if _detail_verbose_logs(analyser):
analyser._log_kv(
"倒计时",
(
"备用并行倒计时候选选择结果"
f" idx={picked_fb_idx}"
f" mm={str(picked_fb.get('mm') or '')}"
f" ss={str(picked_fb.get('ss') or '')}"
f" valid={bool(picked_fb.get('valid'))}"
),
chosen_idx=picked_fb_idx,
chosen_is_primary=bool(picked_fb.get("is_primary")),
chosen_mm=str(picked_fb.get("mm") or ""),
chosen_ss=str(picked_fb.get("ss") or ""),
chosen_score=int(picked_fb.get("score", 0) or 0),
chosen_valid=bool(picked_fb.get("valid")),
candidates=len(countdown_candidate_meta),
)
try:
mm_state, ss_state = _normalize_countdown_pair(countdown_mm_raw, countdown_ss_raw)
room_for_state = str(
@@ -64,53 +64,8 @@ def cut_detail_regions(
if not countdown_enabled:
return countdown_box
# 2. 倒计时区域分割(v2 右侧 chip 左上角带 time:on 调试标签,需避开标签再切数字)
x1, y1, x2, y2 = countdown_box
w = max(1, int(x2 - x1))
h = max(1, int(y2 - y1))
if x1 >= 700:
if renwu == 1:
digit_y1 = min(y2 - 2, y1 + max(1, int(h * 0.28)))
digit_y2 = min(y2, max(digit_y1 + 2, y1 + max(2, int(h * 0.96))))
mm_x1 = min(x2 - 1, x1 + max(1, int(w * 0.08)))
mm_x2 = min(x2, max(mm_x1 + 1, x1 + max(2, int(w * 0.31))))
ss_x1 = min(x2 - 1, x1 + max(1, int(w * 0.40)))
ss_x2 = min(x2, max(ss_x1 + 1, x1 + max(2, int(w * 0.67))))
else:
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,
digit_y1,
mm_x2,
digit_y2,
"",
"福袋倒计时_分钟",
analyser.y_pianyi,
)
analyser.cut_pic(
ss_x1,
digit_y1,
ss_x2,
digit_y2,
"",
"福袋倒计时_秒",
analyser.y_pianyi,
)
# 2. 倒计时只保留整行图,避免分钟/秒小框裁偏后误触发提前参与。
analyser.cut_pic(*countdown_box, "", "福袋倒计时_整行", analyser.y_pianyi)
# 3. 福袋价值
if value_enabled:
@@ -175,7 +175,7 @@ def _read_countdown_digits(
try:
analyser._log_kv(
"倒计时",
"倒计时数字OCR疑似把00识别歪,CV检测覆盖为00",
"倒计时数字OCR非00,忽略CV的00覆盖结果",
picname=name,
ocr_chosen=chosen,
votes=list(votes),
@@ -183,7 +183,7 @@ def _read_countdown_digits(
)
except Exception:
pass
return "00"
break
if len(set(votes)) > 1:
try:
analyser._log_kv(
@@ -202,21 +202,6 @@ def _read_countdown_digits(
raise last_exc
if votes:
for name in reversed(picnames):
cv_digits = _cv_detect_two_zero_digits(name)
if cv_digits:
try:
analyser._log_kv(
"倒计时",
"倒计时数字OCR分歧,CV检测命中00兜底",
picname=name,
votes=list(votes),
raw_results=raw_results[:8],
)
except Exception:
pass
return cv_digits
if picnames:
primary_votes = [
digits
+22 -42
View File
@@ -2,8 +2,8 @@
覆盖:
- _select_countdown_box 4 种 renwu 值返回正确常量
- cut_detail_regions 调用 cut_pic 4 次(内容 + 分钟 + 秒 + 价值)
- 倒计时分割坐标(分钟 0~26%,秒 38%~64%)正确
- cut_detail_regions 调用 cut_pic 3 次(内容 + 整行倒计时 + 价值)
- 倒计时不再分割小框,避免裁偏误识别
- save_debug_images 开关效果
"""
from __future__ import annotations
@@ -60,11 +60,11 @@ class TestCutDetailRegions:
result = cut_detail_regions(a, renwu=2)
assert result == COUNTDOWN_1110_1230
def test_calls_cut_pic_4_times(self):
"""内容 + 分钟 + 秒 + 价值 = 4 次 cut_pic 调用。"""
def test_calls_cut_pic_3_times(self):
"""内容 + 整行倒计时 + 价值 = 3 次 cut_pic 调用。"""
a = _mk_analyser()
cut_detail_regions(a, renwu=2)
assert a.cut_pic.call_count == 4
assert a.cut_pic.call_count == 3
def test_cut_names_in_order(self):
a = _mk_analyser()
@@ -72,57 +72,38 @@ class TestCutDetailRegions:
# 第 1 个 positional arg 是坐标,第 6 个是 name
# 调用签名:cut_pic(x1, y1, x2, y2, target, name, y_pianyi)
names = [c.args[5] for c in a.cut_pic.call_args_list]
assert names == ["福袋内容", "福袋倒计时_分钟", "福袋倒计时_秒", "福袋价值"]
assert names == ["福袋内容", "福袋倒计时_整行", "福袋价值"]
def test_countdown_split_ratio(self):
"""倒计时 box 应按分钟 0~26%,秒 38%~64% 切分。"""
def test_countdown_uses_full_line_region(self):
"""倒计时只切整行,不再分割分钟/秒小框。"""
a = _mk_analyser()
from douyin.fudai.core.coords import COUNTDOWN_1110_1230
x1, y1, x2, y2 = COUNTDOWN_1110_1230
w = x2 - x1
mm_x2 = x1 + int(w * 0.26)
ss_x1 = x1 + int(w * 0.38)
ss_x2 = x1 + int(w * 0.64)
cut_detail_regions(a, renwu=2)
# 倒计时分钟 = 第 2 次 cut_pic 调用
mm_call = a.cut_pic.call_args_list[1]
assert mm_call.args[0] == x1
assert mm_call.args[2] == mm_x2
countdown_call = a.cut_pic.call_args_list[1]
assert countdown_call.args[:4] == COUNTDOWN_1110_1230
assert countdown_call.args[5] == "福袋倒计时_整行"
# 倒计时秒 = 第 3 次调用
ss_call = a.cut_pic.call_args_list[2]
assert ss_call.args[0] == ss_x1
assert ss_call.args[2] == ss_x2
def test_profile_countdown_vertical_crop_skips_left_label_for_v2_chip(self):
def test_profile_countdown_uses_full_line_for_v2_chip(self):
a = _mk_analyser()
profile = {"countdown_full": (760, 1328, 1038, 1398)}
cut_detail_regions(a, renwu=2, profile=profile)
mm_call = a.cut_pic.call_args_list[1]
ss_call = a.cut_pic.call_args_list[2]
assert mm_call.args[:4] == (793, 1358, 860, 1398)
assert ss_call.args[:4] == (876, 1358, 949, 1398)
countdown_call = a.cut_pic.call_args_list[1]
assert countdown_call.args[:4] == (760, 1328, 1038, 1398)
assert countdown_call.args[5] == "福袋倒计时_整行"
def test_v2_two_task_tall_profile_skips_left_label_and_uses_lower_digit_band(self):
def test_v2_two_task_tall_profile_uses_full_line(self):
a = _mk_analyser()
profile = {"countdown_full": (760, 1265, 1040, 1398)}
cut_detail_regions(a, renwu=2, profile=profile)
mm_call = a.cut_pic.call_args_list[1]
ss_call = a.cut_pic.call_args_list[2]
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]
countdown_call = a.cut_pic.call_args_list[1]
assert countdown_call.args[:4] == (760, 1265, 1040, 1398)
assert countdown_call.args[5] == "福袋倒计时_整行"
def test_save_debug_images_disabled_default(self):
a = _mk_analyser()
@@ -153,10 +134,9 @@ class TestCutDetailRegions:
result = cut_detail_regions(a, renwu=1, profile=profile)
assert result == (700, 1390, 990, 1470)
mm_call = a.cut_pic.call_args_list[1]
ss_call = a.cut_pic.call_args_list[2]
assert mm_call.args[:4] == (723, 1412, 789, 1466)
assert ss_call.args[:4] == (816, 1412, 894, 1466)
countdown_call = a.cut_pic.call_args_list[1]
assert countdown_call.args[:4] == (700, 1390, 990, 1470)
assert countdown_call.args[5] == "福袋倒计时_整行"
def test_renwu_3_uses_correct_box(self):
a = _mk_analyser()
+5 -9
View File
@@ -367,7 +367,7 @@ def test_task_list_ocr_critical_path_requires_explicit_opt_in(monkeypatch):
assert _should_schedule_task_list_ocr(analyser, disabled_switches) is False
def test_countdown_full_ocr_is_not_in_detail_critical_path_by_default(monkeypatch):
def test_countdown_full_ocr_is_in_detail_critical_path_by_default(monkeypatch):
from douyin.fudai.douyin_fudai_contain_impl import (
_should_schedule_countdown_full_ocr,
)
@@ -383,10 +383,10 @@ def test_countdown_full_ocr_is_not_in_detail_critical_path_by_default(monkeypatc
{"fudai_detail_ocr_countdown_enabled": True}
)
assert _should_schedule_countdown_full_ocr(SimpleNamespace(), switches) is False
assert _should_schedule_countdown_full_ocr(SimpleNamespace(), switches) is True
def test_countdown_full_ocr_critical_path_requires_explicit_opt_in(monkeypatch):
def test_countdown_full_ocr_critical_path_respects_countdown_switch(monkeypatch):
from douyin.fudai.douyin_fudai_contain_impl import (
_should_schedule_countdown_full_ocr,
)
@@ -405,12 +405,8 @@ def test_countdown_full_ocr_critical_path_requires_explicit_opt_in(monkeypatch):
{"fudai_detail_ocr_countdown_enabled": False}
)
analyser = SimpleNamespace(
fudai_detail_countdown_full_ocr_in_critical_path_enabled=True,
)
assert _should_schedule_countdown_full_ocr(analyser, switches) is True
assert _should_schedule_countdown_full_ocr(analyser, disabled_switches) is False
assert _should_schedule_countdown_full_ocr(SimpleNamespace(), switches) is True
assert _should_schedule_countdown_full_ocr(SimpleNamespace(), disabled_switches) is False
def test_countdown_text_fallback_uses_existing_ocr_without_extra_ocr():
+4 -4
View File
@@ -249,7 +249,7 @@ class TestOcrCountdown:
2,
)
def test_read_countdown_digits_uses_cv_zero_when_ocr_ties(self):
def test_read_countdown_digits_tie_prefers_primary_over_cv_zero(self):
analyser = _mk_analyser()
analyser.operation.analyse_pic_digits = MagicMock(
side_effect=["09", "09", "09", "00", "00", "00"]
@@ -263,7 +263,7 @@ class TestOcrCountdown:
analyser,
"福袋倒计时_分钟_preprocessed",
fallback_picnames=("福袋倒计时_分钟",),
) == "00"
) == "09"
def test_read_countdown_digits_tie_prefers_consistent_preprocessed(self):
analyser = _mk_analyser()
@@ -281,7 +281,7 @@ class TestOcrCountdown:
fallback_picnames=("福袋倒计时_秒",),
) == "41"
def test_read_countdown_digits_cv_zero_can_override_wrong_ocr_majority(self):
def test_read_countdown_digits_cv_zero_cannot_override_nonzero_majority(self):
analyser = _mk_analyser()
analyser.operation.analyse_pic_digits = MagicMock(
side_effect=["09", "09", "09", "", "", ""]
@@ -295,7 +295,7 @@ class TestOcrCountdown:
analyser,
"福袋倒计时_分钟_preprocessed",
fallback_picnames=("福袋倒计时_分钟",),
) == "00"
) == "09"
def test_cv_detect_two_zero_digits_on_current_minute_crop(self):
assert _cv_detect_two_zero_digits("福袋倒计时_分钟") in ("", "00")