fix false fudai detail pixel detection

This commit is contained in:
Your Name committed 2026-06-04 11:51:12 +08:00
1 parent 1d564000ca
commit f07fbb305b
3 files changed
+144 -12

No files matched your search

+10 -7
View File
@@ -15,7 +15,7 @@ from typing import Any
from ._common import _ensure_detection_cache
def check_detail_height(analyser: Any) -> int:
def check_detail_height(analyser: Any, pic_rgb: Any = None) -> int:
"""Detect how many tasks are required in the fudai detail popup.
Returns:
@@ -33,7 +33,7 @@ def check_detail_height(analyser: Any) -> int:
if ui_mode == "legacy":
return _check_detail_task_count_legacy_pixels(analyser)
detected_v2_template = _check_detail_task_count_v2(analyser)
detected_v2_template = _check_detail_task_count_v2(analyser, pic_rgb=pic_rgb)
if detected_v2_template:
return detected_v2_template
@@ -432,7 +432,7 @@ def _check_detail_task_count_v2_pixels(analyser: Any) -> int:
return detected
def _check_detail_task_count_v2(analyser: Any) -> int:
def _check_detail_task_count_v2(analyser: Any, pic_rgb: Any = None) -> int:
"""Fast v2 detail task-count recognition by matching the task-count digit only."""
try:
import cv2 # type: ignore[import-untyped]
@@ -441,10 +441,13 @@ def _check_detail_task_count_v2(analyser: Any) -> int:
from douyin.core import path_config
from douyin.fudai.core.coords import DETAIL_UI_V2_0, DETAIL_UI_V2_0_ONE_TASK
pic_path = path_config.get_screenshot_path()
if not os.path.exists(pic_path):
return 0
pic = Image.open(pic_path).convert("RGB")
if pic_rgb is not None:
pic = pic_rgb.convert("RGB") if hasattr(pic_rgb, "convert") else Image.fromarray(pic_rgb).convert("RGB")
else:
pic_path = path_config.get_screenshot_path()
if not os.path.exists(pic_path):
return 0
pic = Image.open(pic_path).convert("RGB")
pic_rgb = np.asarray(pic)
pic_gray = cv2.cvtColor(pic_rgb, cv2.COLOR_RGB2GRAY)
+51 -5
View File
@@ -110,6 +110,18 @@ def _save_pixel_stage_overview(
get_detail_task_count_digit_box(tuple(DETAIL_UI_V2_0.get("task_count") or (860, 1770, 1035, 1875))),
)
else:
if "has_fudai_detail" in details:
from douyin.detection.detection_pkg.detail import get_detail_task_count_digit_box
from douyin.fudai.core.coords import DETAIL_UI_V2_0, DETAIL_UI_V2_0_ONE_TASK
regions["task_count_one"] = (
"has_fudai_detail",
get_detail_task_count_digit_box(tuple(DETAIL_UI_V2_0_ONE_TASK.get("task_count") or (890, 1855, 1040, 1960))),
)
regions["task_count_two"] = (
"has_fudai_detail",
get_detail_task_count_digit_box(tuple(DETAIL_UI_V2_0.get("task_count") or (860, 1770, 1035, 1875))),
)
if details.get("has_coupon_bg", {}).get("method") != "disabled":
regions["coupon"] = ("has_coupon_bg", get_pixel_region("coupon_popup", (9, 1173, 1079, 2255)))
if details.get("has_redpacket_bg", {}).get("method") != "disabled":
@@ -361,6 +373,38 @@ def detect_fudai_detail_page(
- method: 检测方法("task_count")
- task_count: 任务数量(0/1/2/3)
"""
def _has_detail_panel_chrome(pic_rgb: Image.Image) -> tuple[bool, dict]:
"""Confirm the v2 detail popup's dark blue-purple panel is present."""
try:
import numpy as np # type: ignore[import-untyped]
arr = np.asarray(pic_rgb.convert("RGB")).astype("int16")
height, width = arr.shape[:2]
rx = max(1, int(_resolution_ratio_x or width or 1080))
ry = max(1, int(_resolution_ratio_y or height or 2400))
x1 = max(0, 30 * rx // 1080)
x2 = min(width, 1050 * rx // 1080)
y1 = max(0, 1200 * ry // 2400)
y2 = min(height, 1700 * ry // 2400)
if x1 >= x2 or y1 >= y2:
return False, {"panel_reason": "invalid_panel_box"}
roi = arr[y1:y2, x1:x2]
r, g, b = roi[:, :, 0], roi[:, :, 1], roi[:, :, 2]
bluepurple_ratio = float(
(
(r < 95)
& (g < 85)
& (b > 45)
& (b > r * 0.8)
).mean()
)
return bluepurple_ratio >= 0.45, {
"panel_box": (x1, y1, x2, y2),
"panel_bluepurple_ratio": round(bluepurple_ratio, 4),
}
except Exception as exc:
return False, {"panel_reason": f"panel_exception: {exc}"}
# ---------- 任务数量检测 ----------
if analyser is None:
# analyser 参数必需
@@ -376,17 +420,17 @@ def detect_fudai_detail_page(
from douyin.detection.douyin_detection import check_detail_height
# 执行任务数量检测
task_count = int(check_detail_height(analyser) or 0)
task_count = int(check_detail_height(analyser, pic_rgb=_pic_rgb) or 0)
# 判断是否在福袋详情页
# 如果任务数量 <= 0,则认为不在福袋详情页
# 如果任务数量 >= 1,则认为在福袋详情页
is_in_detail = task_count >= 1
panel_ok, panel_info = _has_detail_panel_chrome(_pic_rgb)
is_in_detail = task_count >= 1 and panel_ok
if return_info:
return is_in_detail, {
"method": "task_count",
"task_count": task_count,
**panel_info,
"reason": None if is_in_detail else "task_count_or_panel_not_matched",
}
return is_in_detail
except Exception as e: # type: ignore[general-exception]
@@ -602,6 +646,8 @@ def read_pixel_stage_state_from_screenshot(
"confidence"
), # 添加confidence支持(用于像素检测)
"task_count": info.get("task_count"), # 添加task_count支持
"panel_bluepurple_ratio": info.get("panel_bluepurple_ratio"),
"panel_box": info.get("panel_box"),
"red_ratio": info.get("red_ratio"), # 添加red_ratio支持
"white_ratio": info.get("white_ratio"),
"effective_threshold": info.get("effective_threshold"),