收口像素检测调试图输出
This commit is contained in:
1 parent
3bcb5cb259
commit
40f9812ab1
5 files changed
+35
-6
No files matched your search
@@ -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]:
|
||||
"""检测粉丝团加入:大片红色区域。
|
||||
|
||||
|
||||
@@ -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 版本检测对应按钮颜色。
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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()
|
||||
|
||||
@@ -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 模块测试。"""
|
||||
|
||||
Reference in new issue
Block a user