expose fudai detail thresholds and regions
This commit is contained in:
1 parent
37a2f94486
commit
9b03556b7d
14 files changed
+293
-18
No files matched your search
@@ -68,6 +68,9 @@ def apply_fudai_defaults(self: Any) -> None:
|
||||
self.attend_button_red_ratio_threshold = 0.25
|
||||
self.fansclub_join_red_ratio_threshold = 0.25
|
||||
self.live_room_match_threshold = 0.8
|
||||
self.fudai_detail_body_bluepurple_threshold = 0.45
|
||||
self.fudai_detail_body_dark_threshold = 0.35
|
||||
self.fudai_task_status_template_threshold = 0.26
|
||||
self.fudai_template_match_enabled = False
|
||||
self.fudai_template_match_threshold = 0.7
|
||||
self.fudai_detail_ui_mode = "auto"
|
||||
|
||||
@@ -434,7 +434,12 @@ def _check_detail_task_count_v2_pixels(analyser: Any) -> int:
|
||||
|
||||
def get_detail_task_status_search_box() -> tuple[int, int, int, int]:
|
||||
"""Unified v2 task-status area; two-task height contains both status words."""
|
||||
return (820, 1815, 1050, 2035)
|
||||
try:
|
||||
from douyin.fudai.core.coords import get_pixel_region
|
||||
|
||||
return get_pixel_region("fudai_task_status", (820, 1815, 1050, 2035))
|
||||
except Exception:
|
||||
return (820, 1815, 1050, 2035)
|
||||
|
||||
|
||||
def _check_detail_task_count_v2(analyser: Any, pic_rgb: Any = None) -> int:
|
||||
@@ -477,6 +482,7 @@ def _check_detail_task_count_v2(analyser: Any, pic_rgb: Any = None) -> int:
|
||||
threshold = float(
|
||||
getattr(analyser, "fudai_task_status_template_threshold", 0.26) or 0.26
|
||||
)
|
||||
threshold = max(0.0, min(1.0, threshold))
|
||||
matches = _collect_task_status_matches(res, threshold, tw, th)
|
||||
best_score = float(matches[0][0]) if matches else -1.0
|
||||
task_count = min(2, len(matches))
|
||||
|
||||
@@ -49,7 +49,18 @@ def _live_room_icon_bbox(width: int, height: int) -> tuple[int, int, int, int]:
|
||||
return _scale_box(get_live_room_icon_bbox(), width, height)
|
||||
|
||||
|
||||
def _detect_fudai_detail_body_colors(pic_rgb: Image.Image) -> tuple[bool, dict]:
|
||||
def _ratio_threshold(analyser: Any, name: str, default: float) -> float:
|
||||
try:
|
||||
value = float(getattr(analyser, name, default) or default)
|
||||
except Exception:
|
||||
value = default
|
||||
return max(0.0, min(1.0, value))
|
||||
|
||||
|
||||
def _detect_fudai_detail_body_colors(
|
||||
pic_rgb: Image.Image,
|
||||
analyser: Any = None,
|
||||
) -> tuple[bool, dict]:
|
||||
"""Use the v2 popup body color volume to identify the fudai detail page."""
|
||||
try:
|
||||
import numpy as np # type: ignore[import-untyped]
|
||||
@@ -80,15 +91,22 @@ def _detect_fudai_detail_body_colors(pic_rgb: Image.Image) -> tuple[bool, dict]:
|
||||
& (b > 35)
|
||||
).mean()
|
||||
)
|
||||
threshold = 0.45
|
||||
detected = bluepurple_ratio >= threshold and dark_ratio >= 0.35
|
||||
bluepurple_threshold = _ratio_threshold(
|
||||
analyser, "fudai_detail_body_bluepurple_threshold", 0.45
|
||||
)
|
||||
dark_threshold = _ratio_threshold(
|
||||
analyser, "fudai_detail_body_dark_threshold", 0.35
|
||||
)
|
||||
detected = bluepurple_ratio >= bluepurple_threshold and dark_ratio >= dark_threshold
|
||||
return detected, {
|
||||
"method": "detail_body_color",
|
||||
"body_box": (x1, y1, x2, y2),
|
||||
"bluepurple_ratio": round(bluepurple_ratio, 4),
|
||||
"dark_ratio": round(dark_ratio, 4),
|
||||
"purple_ratio": round(purple_ratio, 4),
|
||||
"effective_threshold": threshold,
|
||||
"bluepurple_threshold": bluepurple_threshold,
|
||||
"dark_threshold": dark_threshold,
|
||||
"effective_threshold": bluepurple_threshold,
|
||||
"reason": None if detected else "detail_body_color_not_matched",
|
||||
}
|
||||
except Exception as exc:
|
||||
@@ -405,7 +423,7 @@ def detect_fudai_detail_page(
|
||||
- task_count: 任务数量(0/1/2/3)
|
||||
"""
|
||||
if analyser is None:
|
||||
detected, color_info = _detect_fudai_detail_body_colors(_pic_rgb)
|
||||
detected, color_info = _detect_fudai_detail_body_colors(_pic_rgb, analyser)
|
||||
if return_info:
|
||||
return detected, {
|
||||
**color_info,
|
||||
@@ -416,7 +434,7 @@ def detect_fudai_detail_page(
|
||||
try:
|
||||
from douyin.detection.douyin_detection import check_detail_height
|
||||
|
||||
color_detected, color_info = _detect_fudai_detail_body_colors(_pic_rgb)
|
||||
color_detected, color_info = _detect_fudai_detail_body_colors(_pic_rgb, analyser)
|
||||
task_count = int(check_detail_height(analyser, pic_rgb=_pic_rgb) or 0)
|
||||
|
||||
if return_info:
|
||||
|
||||
@@ -102,6 +102,7 @@ LIVE_ROOM_TITLE = (130, 120, 560, 225)
|
||||
|
||||
LIVE_ROOM_ICON_BBOX = (999, 172, 1028, 202)
|
||||
FUDAI_DETAIL_BODY_DEFAULT = (0, 1160, 1080, 2250)
|
||||
FUDAI_TASK_STATUS_DEFAULT = (820, 1815, 1050, 2035)
|
||||
ATTEND_BUTTON_PIXEL_BOX = (200, 2000, 880, 2120)
|
||||
FANSCLUB_JOIN_PIXEL_BOX = (200, 1940, 880, 2140)
|
||||
COUPON_POPUP_BOX = (9, 1173, 1079, 2255)
|
||||
@@ -166,6 +167,7 @@ PIXEL_REGION_DEFAULTS = {
|
||||
"coupon_popup": COUPON_POPUP_BOX,
|
||||
"shopping_redpacket": SHOPPING_REDPACKET_PIXEL_BOX,
|
||||
"fudai_detail_body": FUDAI_DETAIL_BODY_DEFAULT,
|
||||
"fudai_task_status": FUDAI_TASK_STATUS_DEFAULT,
|
||||
"live_room_icon_bbox": LIVE_ROOM_ICON_BBOX,
|
||||
}
|
||||
|
||||
|
||||
@@ -160,6 +160,34 @@ class ConfigManager:
|
||||
threshold = float(config["fansclub_join_red_ratio_threshold"] or 0.25)
|
||||
analyser.fansclub_join_red_ratio_threshold = max(0.0, min(1.0, threshold))
|
||||
|
||||
if "fudai_detail_body_bluepurple_threshold" in config:
|
||||
threshold = float(config["fudai_detail_body_bluepurple_threshold"] or 0.45)
|
||||
analyser.fudai_detail_body_bluepurple_threshold = max(
|
||||
0.0, min(1.0, threshold)
|
||||
)
|
||||
else:
|
||||
analyser.fudai_detail_body_bluepurple_threshold = getattr(
|
||||
analyser, "fudai_detail_body_bluepurple_threshold", 0.45
|
||||
)
|
||||
|
||||
if "fudai_detail_body_dark_threshold" in config:
|
||||
threshold = float(config["fudai_detail_body_dark_threshold"] or 0.35)
|
||||
analyser.fudai_detail_body_dark_threshold = max(0.0, min(1.0, threshold))
|
||||
else:
|
||||
analyser.fudai_detail_body_dark_threshold = getattr(
|
||||
analyser, "fudai_detail_body_dark_threshold", 0.35
|
||||
)
|
||||
|
||||
if "fudai_task_status_template_threshold" in config:
|
||||
threshold = float(config["fudai_task_status_template_threshold"] or 0.26)
|
||||
analyser.fudai_task_status_template_threshold = max(
|
||||
0.0, min(1.0, threshold)
|
||||
)
|
||||
else:
|
||||
analyser.fudai_task_status_template_threshold = getattr(
|
||||
analyser, "fudai_task_status_template_threshold", 0.26
|
||||
)
|
||||
|
||||
if "shopping_redpacket_red_ratio_threshold" in config:
|
||||
threshold = float(config["shopping_redpacket_red_ratio_threshold"] or 0.15)
|
||||
analyser.shopping_redpacket_red_ratio_threshold = max(
|
||||
|
||||
@@ -18,6 +18,8 @@ from __future__ import annotations
|
||||
import tkinter as tk
|
||||
from typing import Callable, Dict
|
||||
|
||||
from douyin.fudai.core.coords import FUDAI_DETAIL_REGION_DEFAULTS, PIXEL_REGION_DEFAULTS
|
||||
|
||||
from .config_io_helpers import (
|
||||
apply_debug_captures_from_cfg,
|
||||
apply_logging_from_cfg,
|
||||
@@ -62,6 +64,7 @@ _REGION_CONFIG_SPECS = (
|
||||
("pixel_regions", "coupon_popup", None),
|
||||
("pixel_regions", "shopping_redpacket", None),
|
||||
("pixel_regions", "fudai_detail_body", None),
|
||||
("pixel_regions", "fudai_task_status", None),
|
||||
("pixel_regions", "live_room_icon_bbox", None),
|
||||
)
|
||||
|
||||
@@ -90,6 +93,25 @@ def _make_region_var_key(root: str, scope: str, name: str | None, axis: str) ->
|
||||
return f"{root}_{scope}_{axis}_var"
|
||||
|
||||
|
||||
def _default_region_values(root: str, scope: str, name: str | None) -> list[int]:
|
||||
if root == "fudai_detail_regions":
|
||||
source = FUDAI_DETAIL_REGION_DEFAULTS.get(scope, {})
|
||||
raw = source.get(name or "", (0, 0, 0, 0)) if isinstance(source, dict) else (0, 0, 0, 0)
|
||||
else:
|
||||
source = PIXEL_REGION_DEFAULTS.get(scope, (0, 0, 0, 0))
|
||||
if isinstance(source, dict):
|
||||
raw = source.get(name or "", (0, 0, 0, 0))
|
||||
else:
|
||||
raw = source
|
||||
try:
|
||||
values = [int(v) for v in list(raw)]
|
||||
except Exception:
|
||||
values = [0, 0, 0, 0]
|
||||
if len(values) < 4:
|
||||
values = (values + [0, 0, 0, 0])[:4]
|
||||
return values
|
||||
|
||||
|
||||
def load_config_to_ui(
|
||||
*,
|
||||
vars_: Dict[str, tk.Variable],
|
||||
@@ -214,6 +236,9 @@ def load_config_to_ui(
|
||||
vars_["fudai_detail_save_debug_images_var"].set(
|
||||
bool(cfg.get("fudai_detail_save_debug_images", False))
|
||||
)
|
||||
vars_["region_coords_edit_enabled_var"].set(
|
||||
bool(cfg.get("region_coords_edit_enabled", False))
|
||||
)
|
||||
for key, default in {
|
||||
"fudai_detail_ocr_content_enabled": True,
|
||||
"fudai_detail_ocr_value_enabled": True,
|
||||
@@ -312,6 +337,15 @@ def load_config_to_ui(
|
||||
vars_["shopping_redpacket_red_ratio_threshold_var"].set(
|
||||
float(cfg.get("shopping_redpacket_red_ratio_threshold", 0.15) or 0.15)
|
||||
)
|
||||
vars_["fudai_detail_body_bluepurple_threshold_var"].set(
|
||||
float(cfg.get("fudai_detail_body_bluepurple_threshold", 0.45) or 0.45)
|
||||
)
|
||||
vars_["fudai_detail_body_dark_threshold_var"].set(
|
||||
float(cfg.get("fudai_detail_body_dark_threshold", 0.35) or 0.35)
|
||||
)
|
||||
vars_["fudai_task_status_template_threshold_var"].set(
|
||||
float(cfg.get("fudai_task_status_template_threshold", 0.26) or 0.26)
|
||||
)
|
||||
# 粉丝团等待/点击延迟配置
|
||||
vars_["fansclub_click_delay_var"].set(float(cfg.get("fansclub_click_delay", 0.6) or 0.6))
|
||||
vars_["fansclub_auto_wait_var"].set(
|
||||
@@ -323,9 +357,9 @@ def load_config_to_ui(
|
||||
vars_["skip_lt_seconds_var"].set(int(cfg.get("skip_if_countdown_lt_seconds", 10) or 10))
|
||||
for root, scope, name in _REGION_CONFIG_SPECS:
|
||||
raw = _deep_get(cfg, root, scope, name) if name else _deep_get(cfg, root, scope)
|
||||
values = list(raw) if isinstance(raw, (list, tuple)) else [0, 0, 0, 0]
|
||||
values = list(raw) if isinstance(raw, (list, tuple)) else _default_region_values(root, scope, name)
|
||||
if len(values) < 4:
|
||||
values = [0, 0, 0, 0]
|
||||
values = _default_region_values(root, scope, name)
|
||||
for idx, axis in enumerate(("x1", "y1", "x2", "y2")):
|
||||
vars_[_make_region_var_key(root, scope, name, axis)].set(int(values[idx] or 0))
|
||||
|
||||
@@ -513,6 +547,9 @@ def save_ui_to_config(
|
||||
cfg2["fudai_detail_save_debug_images"] = bool(
|
||||
vars_["fudai_detail_save_debug_images_var"].get()
|
||||
)
|
||||
cfg2["region_coords_edit_enabled"] = bool(
|
||||
vars_["region_coords_edit_enabled_var"].get()
|
||||
)
|
||||
for key in (
|
||||
"fudai_detail_ocr_content_enabled",
|
||||
"fudai_detail_ocr_value_enabled",
|
||||
@@ -577,6 +614,15 @@ def save_ui_to_config(
|
||||
cfg2["shopping_redpacket_red_ratio_threshold"] = float(
|
||||
vars_["shopping_redpacket_red_ratio_threshold_var"].get() or 0.15
|
||||
)
|
||||
cfg2["fudai_detail_body_bluepurple_threshold"] = float(
|
||||
vars_["fudai_detail_body_bluepurple_threshold_var"].get() or 0.45
|
||||
)
|
||||
cfg2["fudai_detail_body_dark_threshold"] = float(
|
||||
vars_["fudai_detail_body_dark_threshold_var"].get() or 0.35
|
||||
)
|
||||
cfg2["fudai_task_status_template_threshold"] = float(
|
||||
vars_["fudai_task_status_template_threshold_var"].get() or 0.26
|
||||
)
|
||||
# 粉丝团等待/点击延迟配置
|
||||
cfg2["fansclub_click_delay"] = float(vars_["fansclub_click_delay_var"].get() or 0.6)
|
||||
cfg2["fansclub_auto_join_wait_seconds"] = float(
|
||||
|
||||
@@ -9,6 +9,8 @@ from __future__ import annotations
|
||||
import tkinter as tk
|
||||
from typing import Dict
|
||||
|
||||
from douyin.fudai.core.coords import FUDAI_DETAIL_REGION_DEFAULTS, PIXEL_REGION_DEFAULTS
|
||||
|
||||
|
||||
_REGION_CONFIG_SPECS = (
|
||||
("fudai_detail_regions", "legacy", "content"),
|
||||
@@ -44,6 +46,7 @@ _REGION_CONFIG_SPECS = (
|
||||
("pixel_regions", "coupon_popup", None),
|
||||
("pixel_regions", "shopping_redpacket", None),
|
||||
("pixel_regions", "fudai_detail_body", None),
|
||||
("pixel_regions", "fudai_task_status", None),
|
||||
("pixel_regions", "live_room_icon_bbox", None),
|
||||
)
|
||||
|
||||
@@ -63,6 +66,25 @@ def _make_region_var_key(root: str, scope: str, name: str | None, axis: str) ->
|
||||
return f"{root}_{scope}_{axis}_var"
|
||||
|
||||
|
||||
def _default_region_values(root: str, scope: str, name: str | None) -> list[int]:
|
||||
if root == "fudai_detail_regions":
|
||||
source = FUDAI_DETAIL_REGION_DEFAULTS.get(scope, {})
|
||||
raw = source.get(name or "", (0, 0, 0, 0)) if isinstance(source, dict) else (0, 0, 0, 0)
|
||||
else:
|
||||
source = PIXEL_REGION_DEFAULTS.get(scope, (0, 0, 0, 0))
|
||||
if isinstance(source, dict):
|
||||
raw = source.get(name or "", (0, 0, 0, 0))
|
||||
else:
|
||||
raw = source
|
||||
try:
|
||||
values = [int(v) for v in list(raw)]
|
||||
except Exception:
|
||||
values = [0, 0, 0, 0]
|
||||
if len(values) < 4:
|
||||
values = (values + [0, 0, 0, 0])[:4]
|
||||
return values
|
||||
|
||||
|
||||
def build_config_vars(cfg: dict) -> Dict[str, tk.Variable]:
|
||||
"""从 cfg 构建所有 tk Var 实例,返回名→Var 字典。"""
|
||||
y_var = tk.IntVar(value=int(cfg.get("y_pianyi", 0) or 0))
|
||||
@@ -186,6 +208,9 @@ def build_config_vars(cfg: dict) -> Dict[str, tk.Variable]:
|
||||
fudai_detail_save_debug_images_var = tk.BooleanVar(
|
||||
value=bool(cfg.get("fudai_detail_save_debug_images", False))
|
||||
)
|
||||
region_coords_edit_enabled_var = tk.BooleanVar(
|
||||
value=bool(cfg.get("region_coords_edit_enabled", False))
|
||||
)
|
||||
fudai_detail_ocr_content_enabled_var = tk.BooleanVar(
|
||||
value=bool(cfg.get("fudai_detail_ocr_content_enabled", True))
|
||||
)
|
||||
@@ -222,6 +247,15 @@ def build_config_vars(cfg: dict) -> Dict[str, tk.Variable]:
|
||||
live_room_match_threshold_var = tk.DoubleVar(
|
||||
value=float(cfg.get("live_room_match_threshold", 0.8) or 0.8)
|
||||
)
|
||||
fudai_detail_body_bluepurple_threshold_var = tk.DoubleVar(
|
||||
value=float(cfg.get("fudai_detail_body_bluepurple_threshold", 0.45) or 0.45)
|
||||
)
|
||||
fudai_detail_body_dark_threshold_var = tk.DoubleVar(
|
||||
value=float(cfg.get("fudai_detail_body_dark_threshold", 0.35) or 0.35)
|
||||
)
|
||||
fudai_task_status_template_threshold_var = tk.DoubleVar(
|
||||
value=float(cfg.get("fudai_task_status_template_threshold", 0.26) or 0.26)
|
||||
)
|
||||
swipe_duration_ms_var = tk.IntVar(
|
||||
value=int(cfg.get("swipe_duration_ms", 600) or 600)
|
||||
)
|
||||
@@ -507,9 +541,9 @@ def build_config_vars(cfg: dict) -> Dict[str, tk.Variable]:
|
||||
region_vars: Dict[str, tk.Variable] = {}
|
||||
for root, scope, name in _REGION_CONFIG_SPECS:
|
||||
raw = _deep_get(cfg, root, scope, name) if name else _deep_get(cfg, root, scope)
|
||||
values = list(raw) if isinstance(raw, (list, tuple)) else []
|
||||
values = list(raw) if isinstance(raw, (list, tuple)) else _default_region_values(root, scope, name)
|
||||
if len(values) < 4:
|
||||
values = [0, 0, 0, 0]
|
||||
values = _default_region_values(root, scope, name)
|
||||
for idx, axis in enumerate(("x1", "y1", "x2", "y2")):
|
||||
region_vars[_make_region_var_key(root, scope, name, axis)] = tk.IntVar(
|
||||
value=int(values[idx] or 0)
|
||||
@@ -560,6 +594,7 @@ def build_config_vars(cfg: dict) -> Dict[str, tk.Variable]:
|
||||
"fudai_disable_task_recognition_var": fudai_disable_task_recognition_var,
|
||||
"fudai_detail_ui_mode_var": fudai_detail_ui_mode_var,
|
||||
"fudai_detail_save_debug_images_var": fudai_detail_save_debug_images_var,
|
||||
"region_coords_edit_enabled_var": region_coords_edit_enabled_var,
|
||||
"fudai_detail_ocr_content_enabled_var": fudai_detail_ocr_content_enabled_var,
|
||||
"fudai_detail_ocr_value_enabled_var": fudai_detail_ocr_value_enabled_var,
|
||||
"fudai_detail_ocr_countdown_enabled_var": fudai_detail_ocr_countdown_enabled_var,
|
||||
@@ -572,6 +607,9 @@ def build_config_vars(cfg: dict) -> Dict[str, tk.Variable]:
|
||||
"fudai_click_wait_seconds_var": fudai_click_wait_seconds_var,
|
||||
"switch_room_wait_after_stage_diag_seconds_var": switch_room_wait_after_stage_diag_seconds_var,
|
||||
"live_room_match_threshold_var": live_room_match_threshold_var,
|
||||
"fudai_detail_body_bluepurple_threshold_var": fudai_detail_body_bluepurple_threshold_var,
|
||||
"fudai_detail_body_dark_threshold_var": fudai_detail_body_dark_threshold_var,
|
||||
"fudai_task_status_template_threshold_var": fudai_task_status_template_threshold_var,
|
||||
"swipe_duration_ms_var": swipe_duration_ms_var,
|
||||
"swipe_up_start_y_var": swipe_up_start_y_var,
|
||||
"swipe_up_end_y_var": swipe_up_end_y_var,
|
||||
|
||||
@@ -66,6 +66,7 @@ _REGION_SECTIONS = (
|
||||
("pixel_regions", "coupon_popup", None, "优惠券"),
|
||||
("pixel_regions", "shopping_redpacket", None, "购物红包"),
|
||||
("pixel_regions", "fudai_detail_body", None, "详情主体"),
|
||||
("pixel_regions", "fudai_task_status", None, "任务状态达成"),
|
||||
("pixel_regions", "live_room_icon_bbox", None, "直播间图标bbox"),
|
||||
),
|
||||
),
|
||||
@@ -82,16 +83,20 @@ def _add_region_editor(parent: ttk.Frame, *, root: str, scope: str, name: str |
|
||||
row = ttk.Frame(parent)
|
||||
row.pack(fill=X, padx=10, pady=(0, 4))
|
||||
ttk.Label(row, text=f"{label}:", width=14).pack(side=LEFT)
|
||||
inputs = []
|
||||
for axis in ("x1", "y1", "x2", "y2"):
|
||||
ttk.Label(row, text=f"{axis}").pack(side=LEFT, padx=(4, 2))
|
||||
ttk.Spinbox(
|
||||
widget = ttk.Spinbox(
|
||||
row,
|
||||
from_=-9999,
|
||||
to=9999,
|
||||
increment=1,
|
||||
textvariable=vars_[_make_region_var_key(root, scope, name, axis)],
|
||||
width=6,
|
||||
).pack(side=LEFT)
|
||||
)
|
||||
widget.pack(side=LEFT)
|
||||
inputs.append(widget)
|
||||
return inputs
|
||||
|
||||
|
||||
def setup_debug_tab(parent: ttk.Notebook, *, vars_: Dict[str, tk.Variable]) -> ttk.Frame:
|
||||
@@ -383,13 +388,75 @@ def setup_debug_tab(parent: ttk.Notebook, *, vars_: Dict[str, tk.Variable]) -> t
|
||||
row4c, text="(0.0~1.0,默认0.8,多边形区域白色像素比例>=此值判定为在直播间)"
|
||||
).pack(side=LEFT, padx=(6, 0))
|
||||
|
||||
detail_pixel_box = ttk.LabelFrame(fudai_find_box, text="福袋详情页像素判定")
|
||||
detail_pixel_box.pack(fill=X, padx=10, pady=(0, 8))
|
||||
detail_pixel_r1 = ttk.Frame(detail_pixel_box)
|
||||
detail_pixel_r1.pack(fill=X, padx=10, pady=(8, 6))
|
||||
ttk.Label(detail_pixel_r1, text="详情主体蓝紫比例阈值:").pack(side=LEFT)
|
||||
ttk.Spinbox(
|
||||
detail_pixel_r1,
|
||||
from_=0.0,
|
||||
to=1.0,
|
||||
increment=0.01,
|
||||
textvariable=vars_["fudai_detail_body_bluepurple_threshold_var"],
|
||||
width=6,
|
||||
).pack(side=LEFT)
|
||||
ttk.Label(detail_pixel_r1, text="暗色比例阈值:").pack(side=LEFT, padx=(20, 0))
|
||||
ttk.Spinbox(
|
||||
detail_pixel_r1,
|
||||
from_=0.0,
|
||||
to=1.0,
|
||||
increment=0.01,
|
||||
textvariable=vars_["fudai_detail_body_dark_threshold_var"],
|
||||
width=6,
|
||||
).pack(side=LEFT)
|
||||
ttk.Label(detail_pixel_r1, text="“达成”形状匹配阈值:").pack(
|
||||
side=LEFT, padx=(20, 0)
|
||||
)
|
||||
ttk.Spinbox(
|
||||
detail_pixel_r1,
|
||||
from_=0.0,
|
||||
to=1.0,
|
||||
increment=0.01,
|
||||
textvariable=vars_["fudai_task_status_template_threshold_var"],
|
||||
width=6,
|
||||
).pack(side=LEFT)
|
||||
|
||||
region_box = ttk.LabelFrame(debug_container, text="福袋坐标配置")
|
||||
region_box.pack(fill=X, padx=10, pady=(0, 10))
|
||||
region_toggle_row = ttk.Frame(region_box)
|
||||
region_toggle_row.pack(fill=X, padx=10, pady=(8, 4))
|
||||
ttk.Checkbutton(
|
||||
region_toggle_row,
|
||||
text="启用坐标调整(默认关闭,避免滚轮误触)",
|
||||
variable=vars_["region_coords_edit_enabled_var"],
|
||||
).pack(side=LEFT)
|
||||
ttk.Label(
|
||||
region_toggle_row,
|
||||
text="关闭时下方 OCR / 像素坐标全部只读",
|
||||
).pack(side=LEFT, padx=(8, 0))
|
||||
region_widgets = []
|
||||
for section_title, items in _REGION_SECTIONS:
|
||||
section = ttk.LabelFrame(region_box, text=section_title)
|
||||
section.pack(fill=X, padx=10, pady=(8, 6))
|
||||
for root, scope, name, label in items:
|
||||
_add_region_editor(section, root=root, scope=scope, name=name, label=label, vars_=vars_)
|
||||
region_widgets.extend(
|
||||
_add_region_editor(section, root=root, scope=scope, name=name, label=label, vars_=vars_)
|
||||
)
|
||||
|
||||
def _sync_region_editor_state(*_args):
|
||||
state = "normal" if bool(vars_["region_coords_edit_enabled_var"].get()) else "disabled"
|
||||
for widget in region_widgets:
|
||||
try:
|
||||
widget.configure(state=state)
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
try:
|
||||
vars_["region_coords_edit_enabled_var"].trace_add("write", _sync_region_editor_state)
|
||||
except Exception:
|
||||
pass
|
||||
_sync_region_editor_state()
|
||||
|
||||
# 鼠标配置
|
||||
mouse_config_box = ttk.LabelFrame(debug_container, text="鼠标配置")
|
||||
|
||||
@@ -372,6 +372,9 @@ def handle_post(handler, u, runner, csrf_token: str) -> None:
|
||||
"attend_button_red_ratio_threshold",
|
||||
"fansclub_join_red_ratio_threshold",
|
||||
"shopping_redpacket_red_ratio_threshold",
|
||||
"fudai_detail_body_bluepurple_threshold",
|
||||
"fudai_detail_body_dark_threshold",
|
||||
"fudai_task_status_template_threshold",
|
||||
"high_value_fudai_poll_before_seconds",
|
||||
"high_value_room_revisit_min_prize_value",
|
||||
"reservation_back_verify_wait_seconds",
|
||||
@@ -392,6 +395,7 @@ def handle_post(handler, u, runner, csrf_token: str) -> None:
|
||||
"high_value_fudai_enabled",
|
||||
"fudai_disable_content_recognition",
|
||||
"fudai_detail_save_debug_images",
|
||||
"region_coords_edit_enabled",
|
||||
"fudai_detail_ocr_content_enabled",
|
||||
"fudai_detail_ocr_value_enabled",
|
||||
"fudai_detail_ocr_countdown_enabled",
|
||||
@@ -493,6 +497,7 @@ def handle_post(handler, u, runner, csrf_token: str) -> None:
|
||||
"pixel_regions.coupon_popup",
|
||||
"pixel_regions.shopping_redpacket",
|
||||
"pixel_regions.fudai_detail_body",
|
||||
"pixel_regions.fudai_task_status",
|
||||
"pixel_regions.live_room_icon_bbox",
|
||||
}
|
||||
derived_logging_keys = {
|
||||
|
||||
@@ -3,6 +3,7 @@ from __future__ import annotations
|
||||
import json
|
||||
from types import SimpleNamespace
|
||||
|
||||
import pytest
|
||||
from PIL import Image
|
||||
|
||||
|
||||
@@ -247,8 +248,8 @@ def test_v2_task_count_dacheng_shape_real_samples():
|
||||
one_task = Path(
|
||||
r"C:\Users\12742\Desktop\douyin_guaji-main\pic\debug_captures\2026-06-04\20260604_115302_493312_px_pxstage_ov_ok_3.png"
|
||||
)
|
||||
assert two_task.exists()
|
||||
assert one_task.exists()
|
||||
if not two_task.exists() or not one_task.exists():
|
||||
pytest.skip("real fudai task-count samples are not available on this machine")
|
||||
|
||||
analyser = SimpleNamespace(
|
||||
fudai_detail_ui_mode="v2_0",
|
||||
|
||||
@@ -134,6 +134,10 @@ class TestFudaiDetailOcrGuiConfig:
|
||||
"fudai_detail_ocr_button_enabled_var",
|
||||
"fudai_detail_ocr_participants_enabled_var",
|
||||
"fudai_detail_ocr_live_title_enabled_var",
|
||||
"region_coords_edit_enabled_var",
|
||||
"fudai_detail_body_bluepurple_threshold_var",
|
||||
"fudai_detail_body_dark_threshold_var",
|
||||
"fudai_task_status_template_threshold_var",
|
||||
):
|
||||
assert key in vars_
|
||||
|
||||
@@ -154,10 +158,29 @@ class TestFudaiDetailOcrGuiConfig:
|
||||
"fudai_detail_regions_v2_0_two_task_content_x1_var",
|
||||
"fudai_detail_regions_v2_0_one_task_info_line_x1_var",
|
||||
"pixel_regions_lottery_result_pixel_x1_var",
|
||||
"pixel_regions_fudai_task_status_x1_var",
|
||||
"pixel_regions_live_room_icon_bbox_x1_var",
|
||||
):
|
||||
assert key in vars_
|
||||
|
||||
def test_build_config_vars_region_fields_fallback_to_defaults(self, monkeypatch):
|
||||
import tkinter as tk
|
||||
|
||||
from gui.components.config_vars import build_config_vars
|
||||
|
||||
monkeypatch.setattr(tk, "StringVar", lambda value="": MagicMock(get=lambda: value, set=lambda _v: None))
|
||||
monkeypatch.setattr(tk, "BooleanVar", lambda value=False: MagicMock(get=lambda: value, set=lambda _v: None))
|
||||
monkeypatch.setattr(tk, "IntVar", lambda value=0: MagicMock(get=lambda: value, set=lambda _v: None))
|
||||
monkeypatch.setattr(tk, "DoubleVar", lambda value=0.0: MagicMock(get=lambda: value, set=lambda _v: None))
|
||||
|
||||
vars_ = build_config_vars({})
|
||||
|
||||
assert vars_["fudai_detail_regions_legacy_content_x1_var"].get() == 389
|
||||
assert vars_["fudai_detail_regions_v2_0_two_task_content_y1_var"].get() == 1410
|
||||
assert vars_["fudai_detail_regions_v2_0_one_task_info_line_x1_var"].get() == 430
|
||||
assert vars_["pixel_regions_fudai_task_status_x1_var"].get() == 820
|
||||
assert vars_["pixel_regions_live_room_icon_bbox_x1_var"].get() == 999
|
||||
|
||||
|
||||
class TestWriteConfig:
|
||||
def test_write_and_read_roundtrip(self):
|
||||
|
||||
@@ -127,6 +127,10 @@ def test_config_accepts_fudai_detail_v2_ocr_switches_and_ui_mode(monkeypatch):
|
||||
"fudai_detail_ocr_button_enabled": "true",
|
||||
"fudai_detail_ocr_participants_enabled": "false",
|
||||
"fudai_detail_ocr_live_title_enabled": "false",
|
||||
"region_coords_edit_enabled": "true",
|
||||
"fudai_detail_body_bluepurple_threshold": "0.46",
|
||||
"fudai_detail_body_dark_threshold": "0.36",
|
||||
"fudai_task_status_template_threshold": "0.27",
|
||||
}
|
||||
},
|
||||
monkeypatch,
|
||||
@@ -138,6 +142,10 @@ def test_config_accepts_fudai_detail_v2_ocr_switches_and_ui_mode(monkeypatch):
|
||||
assert written["fudai_detail_ocr_content_enabled"] is True
|
||||
assert written["fudai_detail_ocr_button_enabled"] is True
|
||||
assert written["fudai_detail_ocr_participants_enabled"] is False
|
||||
assert written["region_coords_edit_enabled"] is True
|
||||
assert written["fudai_detail_body_bluepurple_threshold"] == 0.46
|
||||
assert written["fudai_detail_body_dark_threshold"] == 0.36
|
||||
assert written["fudai_task_status_template_threshold"] == 0.27
|
||||
|
||||
|
||||
def test_config_accepts_region_coordinate_arrays(monkeypatch):
|
||||
@@ -152,6 +160,7 @@ def test_config_accepts_region_coordinate_arrays(monkeypatch):
|
||||
"config": {
|
||||
"fudai_detail_regions.v2_0_one_task.info_line": [430, 1315, 1055, 1435],
|
||||
"pixel_regions.lottery_result.pixel": ["290", "1300", "790", "1415"],
|
||||
"pixel_regions.fudai_task_status": [820, 1815, 1050, 2035],
|
||||
"pixel_regions.live_room_icon_bbox": [999, 172, 1028, 202],
|
||||
}
|
||||
},
|
||||
@@ -162,6 +171,7 @@ def test_config_accepts_region_coordinate_arrays(monkeypatch):
|
||||
assert obj.get("ok") is True
|
||||
assert written["fudai_detail_regions"]["v2_0_one_task"]["info_line"] == [430, 1315, 1055, 1435]
|
||||
assert written["pixel_regions"]["lottery_result"]["pixel"] == [290, 1300, 790, 1415]
|
||||
assert written["pixel_regions"]["fudai_task_status"] == [820, 1815, 1050, 2035]
|
||||
assert written["pixel_regions"]["live_room_icon_bbox"] == [999, 172, 1028, 202]
|
||||
|
||||
|
||||
@@ -271,7 +281,7 @@ def test_wifi_auto_reconnect_without_adb_returns_422(monkeypatch):
|
||||
assert obj.get("error") == "adb not found"
|
||||
|
||||
|
||||
def test_wifi_auto_reconnect_uses_auto_full_port_scan(monkeypatch):
|
||||
def test_wifi_auto_reconnect_uses_lightweight_ports(monkeypatch):
|
||||
captured = {}
|
||||
|
||||
monkeypatch.setattr(routes, "find_adb_executable", lambda: "adb")
|
||||
@@ -297,7 +307,7 @@ def test_wifi_auto_reconnect_uses_auto_full_port_scan(monkeypatch):
|
||||
|
||||
assert status == 200
|
||||
assert obj.get("ok") is True
|
||||
assert "ports" not in captured
|
||||
assert captured.get("ports") == [39601, 5555, 44219]
|
||||
|
||||
|
||||
def test_wifi_scan_includes_tried_subnets(monkeypatch):
|
||||
|
||||
@@ -54,6 +54,7 @@
|
||||
["pixel_regions.coupon_popup", "优惠券"],
|
||||
["pixel_regions.shopping_redpacket", "购物红包"],
|
||||
["pixel_regions.fudai_detail_body", "详情主体"],
|
||||
["pixel_regions.fudai_task_status", "任务状态达成"],
|
||||
["pixel_regions.live_room_icon_bbox", "直播间图标bbox"],
|
||||
],
|
||||
},
|
||||
@@ -174,6 +175,13 @@
|
||||
<label class="check"><input id="fudai_detail_ocr_participants_enabled" type="checkbox" data-key="fudai_detail_ocr_participants_enabled" data-type="bool" /> <span>人数 OCR(默认关闭)</span></label>
|
||||
<label class="check"><input id="fudai_detail_ocr_live_title_enabled" type="checkbox" data-key="fudai_detail_ocr_live_title_enabled" data-type="bool" /> <span>直播间标题 OCR(默认关闭)</span></label>
|
||||
</div>
|
||||
<div class="row">
|
||||
<label class="label">坐标调整开关</label>
|
||||
<label class="check">
|
||||
<input id="region_coords_edit_enabled" type="checkbox" data-key="region_coords_edit_enabled" data-type="bool" />
|
||||
<span>启用坐标调整(默认关闭,避免滚轮误触)</span>
|
||||
</label>
|
||||
</div>
|
||||
<div class="sectionTitle">福袋坐标配置</div>
|
||||
${regionSectionsHtml}
|
||||
<div class="row">
|
||||
@@ -265,6 +273,21 @@
|
||||
<label class="label">购物红包红色比例阈值</label>
|
||||
<input id="shopping_redpacket_red_ratio_threshold" class="input" data-key="shopping_redpacket_red_ratio_threshold" data-type="float" type="number" min="0" max="1" step="0.01" />
|
||||
</div>
|
||||
<div class="sectionTitle">福袋详情页像素判定</div>
|
||||
<div class="row grid3">
|
||||
<div>
|
||||
<label class="label">详情主体蓝紫比例阈值</label>
|
||||
<input id="fudai_detail_body_bluepurple_threshold" class="input" data-key="fudai_detail_body_bluepurple_threshold" data-type="float" type="number" min="0" max="1" step="0.01" />
|
||||
</div>
|
||||
<div>
|
||||
<label class="label">详情主体暗色比例阈值</label>
|
||||
<input id="fudai_detail_body_dark_threshold" class="input" data-key="fudai_detail_body_dark_threshold" data-type="float" type="number" min="0" max="1" step="0.01" />
|
||||
</div>
|
||||
<div>
|
||||
<label class="label">任务“达成”形状匹配阈值</label>
|
||||
<input id="fudai_task_status_template_threshold" class="input" data-key="fudai_task_status_template_threshold" data-type="float" type="number" min="0" max="1" step="0.01" />
|
||||
</div>
|
||||
</div>
|
||||
<div class="row">
|
||||
<label class="label">直播间匹配阈值</label>
|
||||
<input id="debug_live_room_match_threshold" class="input" data-mirror-key="live_room_match_threshold" type="number" min="0" max="1" step="0.01" value="0.7" />
|
||||
|
||||
@@ -134,6 +134,7 @@ const DEFAULTS = {
|
||||
fudai_disable_content_recognition: false,
|
||||
fudai_detail_ui_mode: "auto",
|
||||
fudai_detail_save_debug_images: false,
|
||||
region_coords_edit_enabled: false,
|
||||
fudai_detail_ocr_content_enabled: true,
|
||||
fudai_detail_ocr_value_enabled: true,
|
||||
fudai_detail_ocr_countdown_enabled: true,
|
||||
@@ -175,6 +176,7 @@ const DEFAULTS = {
|
||||
"pixel_regions.coupon_popup": [9, 1173, 1079, 2255],
|
||||
"pixel_regions.shopping_redpacket": [200, 300, 880, 1400],
|
||||
"pixel_regions.fudai_detail_body": [0, 1160, 1080, 2250],
|
||||
"pixel_regions.fudai_task_status": [820, 1815, 1050, 2035],
|
||||
"pixel_regions.live_room_icon_bbox": [999, 172, 1028, 202],
|
||||
pixel_detect_fudai_icon_enabled: true,
|
||||
pixel_detect_coupon_popup_enabled: true,
|
||||
@@ -189,6 +191,9 @@ const DEFAULTS = {
|
||||
ocr_shopping_redpacket_enabled: false,
|
||||
ocr_stage_page_enabled: true,
|
||||
live_room_match_threshold: 0.8,
|
||||
fudai_detail_body_bluepurple_threshold: 0.45,
|
||||
fudai_detail_body_dark_threshold: 0.35,
|
||||
fudai_task_status_template_threshold: 0.26,
|
||||
reservation_back_swipe_delay: 0.6,
|
||||
|
||||
// 定时禁抢福袋(默认 2-7 点)
|
||||
|
||||
Reference in new issue
Block a user