From 40f9812ab1073e3f0405f6c9edc05618067b6b11 Mon Sep 17 00:00:00 2001 From: Your Name Date: Wed, 3 Jun 2026 12:05:27 +0800 Subject: [PATCH] =?UTF-8?q?=E6=94=B6=E5=8F=A3=E5=83=8F=E7=B4=A0=E6=A3=80?= =?UTF-8?q?=E6=B5=8B=E8=B0=83=E8=AF=95=E5=9B=BE=E8=BE=93=E5=87=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- douyin/detection/pixel/buttons.py | 4 +-- douyin/detection/pixel/popups.py | 2 +- douyin/other/douyin_popups.py | 5 +++- .../direct_attend.py | 4 +-- tests/test_detection_pixel.py | 26 +++++++++++++++++++ 5 files changed, 35 insertions(+), 6 deletions(-) diff --git a/douyin/detection/pixel/buttons.py b/douyin/detection/pixel/buttons.py index a261ed5..f5b811c 100644 --- a/douyin/detection/pixel/buttons.py +++ b/douyin/detection/pixel/buttons.py @@ -24,7 +24,7 @@ def detect_attend_button_red_area( return_info: bool = False, red_ratio_threshold: float | None = None, analyser: Any = None, - save_debug: bool = True, + save_debug: bool = False, ) -> bool | tuple[bool, dict]: """检测参与按钮:大片红色区域。 @@ -181,7 +181,7 @@ def detect_fansclub_join_red_area( return_info: bool = False, red_ratio_threshold: float | None = None, analyser: Any = None, - save_debug: bool = True, + save_debug: bool = False, ) -> bool | tuple[bool, dict]: """检测粉丝团加入:大片红色区域。 diff --git a/douyin/detection/pixel/popups.py b/douyin/detection/pixel/popups.py index ec76936..1b9614f 100644 --- a/douyin/detection/pixel/popups.py +++ b/douyin/detection/pixel/popups.py @@ -296,7 +296,7 @@ def detect_lucky_draw_result_popup( red_ratio_threshold: float = 0.8, return_info: bool = False, analyser: Any = None, - save_debug: bool = True, + save_debug: bool = False, ) -> bool | tuple[bool, dict]: """检测抽奖结果弹窗:"我知道了"按钮区域,按 UI 版本检测对应按钮颜色。 diff --git a/douyin/other/douyin_popups.py b/douyin/other/douyin_popups.py index 12352e7..772088b 100644 --- a/douyin/other/douyin_popups.py +++ b/douyin/other/douyin_popups.py @@ -41,7 +41,9 @@ def check_coupon_popup(analyser) -> bool: pic_rgb = pic.convert("RGB") finally: pic.close() - template_matched = bool(douyin_pixel.detect_coupon_popup_background(pic_rgb)) + template_matched = bool( + douyin_pixel.detect_coupon_popup_background(pic_rgb, save_debug=False) + ) except (OSError, IOError, SyntaxError) as e: # Handle truncated image files try: @@ -245,6 +247,7 @@ def check_shopping_redpacket_popup(analyser) -> bool: pic_rgb, red_ratio_threshold=redpacket_threshold, analyser=analyser, + save_debug=False, ) ) pixel_elapsed = time.time() - pixel_check_start diff --git a/douyin/reservation/douyin_reservation_handler_pkg/direct_attend.py b/douyin/reservation/douyin_reservation_handler_pkg/direct_attend.py index a4a3ded..afd0c8c 100644 --- a/douyin/reservation/douyin_reservation_handler_pkg/direct_attend.py +++ b/douyin/reservation/douyin_reservation_handler_pkg/direct_attend.py @@ -211,7 +211,7 @@ def handle_reservation_direct_attend(analyser: Any) -> None: try: button_result = douyin_pixel.detect_attend_button_red_area( - pic_rgb, return_info=True, analyser=analyser + pic_rgb, return_info=True, analyser=analyser, save_debug=False ) finally: pic_rgb.close() @@ -309,7 +309,7 @@ def handle_reservation_direct_attend(analyser: Any) -> None: pic_rgb2 = Image.open(screenshot_path2) # type: ignore[attr-defined] try: button_result2 = douyin_pixel.detect_attend_button_red_area( - pic_rgb2, return_info=True, analyser=analyser + pic_rgb2, return_info=True, analyser=analyser, save_debug=False ) finally: pic_rgb2.close() diff --git a/tests/test_detection_pixel.py b/tests/test_detection_pixel.py index 3a7bf88..15ec308 100644 --- a/tests/test_detection_pixel.py +++ b/tests/test_detection_pixel.py @@ -102,6 +102,32 @@ class TestPixelPopups: assert info["white_ratio"] >= 0.8 assert info["pixel_style"] == "red" + def test_lucky_draw_result_pixel_debug_disabled_by_default(self, monkeypatch): + from douyin.detection.pixel.popups import detect_lucky_draw_result_popup + from douyin.fudai.core.coords import LOTTERY_RESULT_CONFIRM_BUTTON_PIXEL_V2 + + calls = [] + monkeypatch.setattr( + "douyin.handlers.douyin_screenshot_manager.save_debug_image", + lambda *args, **kwargs: calls.append(kwargs) or "debug.png", + ) + + img = Image.new("RGB", (1080, 2400), (20, 20, 20)) + x1, y1, x2, y2 = LOTTERY_RESULT_CONFIRM_BUTTON_PIXEL_V2 + for y in range(y1, y2): + for x in range(x1, x2): + img.putpixel((x, y), (245, 245, 245)) + + detected, info = detect_lucky_draw_result_popup( + img, + return_info=True, + analyser=SimpleNamespace(fudai_detail_ui_mode="v2_0"), + ) + + assert detected is True + assert info["pixel_style"] == "white" + assert calls == [] + class TestPixelButtons: """pixel/buttons 模块测试。"""