fix false fudai detail pixel detection
This commit is contained in:
1 parent
1d564000ca
commit
f07fbb305b
3 files changed
+144
-12
No files matched your search
@@ -170,6 +170,36 @@ class TestPixelStage:
|
||||
|
||||
assert callable(detect_fudai_detail_page)
|
||||
|
||||
def test_detect_fudai_detail_page_uses_current_frame(self, tmp_path, monkeypatch):
|
||||
from PIL import ImageDraw
|
||||
from douyin.detection.pixel.stage import detect_fudai_detail_page
|
||||
from douyin.core import path_config
|
||||
|
||||
stale_screenshot = tmp_path / "stale_detail_like.png"
|
||||
stale = Image.new("RGB", (1080, 2400), (10, 15, 70))
|
||||
draw = ImageDraw.Draw(stale)
|
||||
draw.text((976, 1871), "1", fill=(255, 90, 140))
|
||||
stale.save(stale_screenshot)
|
||||
monkeypatch.setattr(path_config, "get_screenshot_path", lambda: str(stale_screenshot))
|
||||
|
||||
current_live_room = Image.new("RGB", (1080, 2400), (240, 240, 240))
|
||||
analyser = SimpleNamespace(
|
||||
fudai_detail_ui_mode="v2_0",
|
||||
resolution_ratio_x=1080,
|
||||
resolution_ratio_y=2400,
|
||||
_log_kv=lambda *_args, **_kwargs: None,
|
||||
)
|
||||
|
||||
detected, info = detect_fudai_detail_page(
|
||||
current_live_room,
|
||||
return_info=True,
|
||||
analyser=analyser,
|
||||
)
|
||||
|
||||
assert detected is False
|
||||
assert info["task_count"] == 0
|
||||
assert info["panel_bluepurple_ratio"] < 0.45
|
||||
|
||||
def test_read_pixel_stage_state_exists(self):
|
||||
from douyin.detection.pixel.stage import read_pixel_stage_state_from_screenshot
|
||||
|
||||
@@ -296,6 +326,59 @@ class TestPixelStage:
|
||||
# Successful live-room icon detection is still annotated.
|
||||
assert overview.getpixel((1002, 172)) == (0, 220, 80)
|
||||
|
||||
def test_pixel_stage_overview_draws_task_count_candidates_when_not_detail(self, tmp_path, monkeypatch):
|
||||
from douyin.detection.pixel.stage import _save_pixel_stage_overview
|
||||
|
||||
debug_dir = tmp_path / "debug"
|
||||
debug_dir.mkdir()
|
||||
saved_images = []
|
||||
|
||||
def fake_save_debug_image(image, **kwargs):
|
||||
saved_images.append(image.copy())
|
||||
return str(debug_dir / "20260604_px_pxstage_ov_ok_1.png")
|
||||
|
||||
monkeypatch.setattr(
|
||||
"douyin.handlers.screenshot_manager.save_image_helpers.is_debug_captures_enabled",
|
||||
lambda: True,
|
||||
)
|
||||
monkeypatch.setattr(
|
||||
"douyin.handlers.screenshot_manager.paths.get_debug_captures_dir",
|
||||
lambda: str(debug_dir),
|
||||
)
|
||||
monkeypatch.setattr(
|
||||
"douyin.handlers.douyin_screenshot_manager.save_debug_image",
|
||||
fake_save_debug_image,
|
||||
)
|
||||
|
||||
image = Image.new("RGB", (1080, 2400), (20, 20, 20))
|
||||
_save_pixel_stage_overview(
|
||||
image,
|
||||
{
|
||||
"has_coupon_bg": False,
|
||||
"has_redpacket_bg": False,
|
||||
"has_lucky_draw_result": False,
|
||||
"has_attend_button_red": False,
|
||||
"has_fansclub_join_red": False,
|
||||
"has_fudai_detail": False,
|
||||
"has_live_room_pixel": True,
|
||||
},
|
||||
{
|
||||
"has_coupon_bg": {"method": "template_match", "template_score": 0.1},
|
||||
"has_redpacket_bg": {"method": "disabled"},
|
||||
"has_lucky_draw_result": {"method": "pixel_detect", "red_ratio": 0.0},
|
||||
"has_attend_button_red": {"method": "pixel_detect", "red_ratio": 0.0},
|
||||
"has_fansclub_join_red": {"method": "pixel_detect", "red_ratio": 0.0},
|
||||
"has_fudai_detail": {"method": "task_count", "task_count": 0},
|
||||
"has_live_room_pixel": {"method": "pixel_detection", "confidence": 0.95},
|
||||
},
|
||||
analyser=SimpleNamespace(fudai_detail_ui_mode="v2_0"),
|
||||
)
|
||||
|
||||
assert saved_images
|
||||
overview = saved_images[0]
|
||||
assert overview.getpixel((977, 1874)) == (255, 70, 70)
|
||||
assert overview.getpixel((975, 1817)) == (255, 70, 70)
|
||||
|
||||
|
||||
class TestPixelCommon:
|
||||
"""pixel/_common 模块测试。"""
|
||||
|
||||
Reference in new issue
Block a user