优化:添加购物红包背景红色占比阈值配置,增强红包弹窗检测功能
This commit is contained in:
1 parent
d31a3ffee3
commit
c79c50ffe4
5 files changed
+83
-6
No files matched your search
+2
-1
@@ -222,5 +222,6 @@
|
||||
"high_value_room_revisit_min_prize_value": 1000.0,
|
||||
"high_value_room_revisit_max_age_days": 1,
|
||||
"swipe_up_start_y": 1200,
|
||||
"swipe_up_end_y": 600
|
||||
"swipe_up_end_y": 600,
|
||||
"shopping_redpacket_red_ratio_threshold": 0.5
|
||||
}
|
||||
@@ -173,7 +173,10 @@ def detect_coupon_popup_background(
|
||||
|
||||
|
||||
def detect_redpacket_popup_background(
|
||||
pic_rgb: Image.Image, return_info: bool = False
|
||||
pic_rgb: Image.Image,
|
||||
return_info: bool = False,
|
||||
red_ratio_threshold: float | None = None,
|
||||
analyser: Any = None,
|
||||
) -> bool | tuple[bool, dict]:
|
||||
"""中央购物红包弹窗检测:检测中央大红包区域的红色占比。
|
||||
|
||||
@@ -189,6 +192,8 @@ def detect_redpacket_popup_background(
|
||||
参数:
|
||||
pic_rgb: RGB格式的整屏截图
|
||||
return_info: 是否返回详细信息(包含红色比例)
|
||||
red_ratio_threshold: 红色占比阈值(默认0.15,若提供则使用)
|
||||
analyser: analyser对象,用于读取配置阈值
|
||||
|
||||
返回:
|
||||
bool: 是否检测到购物红包背景(return_info=False时)
|
||||
@@ -251,7 +256,19 @@ def detect_redpacket_popup_background(
|
||||
red_ratio = red_pixels / total_pixels if total_pixels > 0 else 0
|
||||
|
||||
# 阈值:至少15%的像素满足红色特征
|
||||
result = bool(red_ratio > 0.15)
|
||||
if red_ratio_threshold is not None:
|
||||
threshold = float(red_ratio_threshold)
|
||||
elif analyser is not None:
|
||||
try:
|
||||
threshold = float(
|
||||
getattr(analyser, "shopping_redpacket_red_ratio_threshold", 0.15)
|
||||
or 0.15
|
||||
)
|
||||
except Exception as e: # type: ignore[general-exception]
|
||||
threshold = 0.15
|
||||
else:
|
||||
threshold = 0.15
|
||||
result = bool(red_ratio > threshold)
|
||||
|
||||
if return_info:
|
||||
reason_value: Optional[str] = (
|
||||
@@ -260,7 +277,7 @@ def detect_redpacket_popup_background(
|
||||
return result, {
|
||||
"method": "pixel_detection",
|
||||
"red_ratio": float(red_ratio),
|
||||
"effective_threshold": 0.15,
|
||||
"effective_threshold": threshold,
|
||||
"reason": reason_value,
|
||||
}
|
||||
return result
|
||||
@@ -1030,6 +1047,7 @@ def read_pixel_stage_state_from_screenshot(
|
||||
coupon_threshold = None
|
||||
attend_button_threshold = None
|
||||
fansclub_threshold = None
|
||||
redpacket_threshold = None
|
||||
live_room_pixel_threshold = None
|
||||
if analyser is not None:
|
||||
try:
|
||||
@@ -1050,6 +1068,13 @@ def read_pixel_stage_state_from_screenshot(
|
||||
)
|
||||
except Exception as e: # type: ignore[general-exception]
|
||||
pass
|
||||
try:
|
||||
redpacket_threshold = float(
|
||||
getattr(analyser, "shopping_redpacket_red_ratio_threshold", None)
|
||||
or 0.15
|
||||
)
|
||||
except Exception as e: # type: ignore[general-exception]
|
||||
pass
|
||||
try:
|
||||
live_room_pixel_threshold = float(
|
||||
getattr(analyser, "live_room_match_threshold", None) or 0.8
|
||||
@@ -1082,7 +1107,10 @@ def read_pixel_stage_state_from_screenshot(
|
||||
analyser=analyser,
|
||||
),
|
||||
"has_redpacket_bg": lambda pic: detect_redpacket_popup_background(
|
||||
pic, return_info=True
|
||||
pic,
|
||||
return_info=True,
|
||||
red_ratio_threshold=redpacket_threshold,
|
||||
analyser=analyser,
|
||||
),
|
||||
"has_lucky_draw_result": lambda pic: detect_lucky_draw_result_popup(
|
||||
pic, lucky_draw_red_ratio_threshold, return_info=True
|
||||
|
||||
@@ -209,7 +209,20 @@ def check_shopping_redpacket_popup(analyser) -> bool:
|
||||
pic = Image.open(pic_path)
|
||||
pic.load() # Force load to catch truncated files early
|
||||
pic = pic.convert("RGB")
|
||||
has_popup_pixel = bool(douyin_pixel.detect_redpacket_popup_background(pic))
|
||||
try:
|
||||
redpacket_threshold = float(
|
||||
getattr(analyser, "shopping_redpacket_red_ratio_threshold", None)
|
||||
or 0.15
|
||||
)
|
||||
except Exception:
|
||||
redpacket_threshold = 0.15
|
||||
has_popup_pixel = bool(
|
||||
douyin_pixel.detect_redpacket_popup_background(
|
||||
pic,
|
||||
red_ratio_threshold=redpacket_threshold,
|
||||
analyser=analyser,
|
||||
)
|
||||
)
|
||||
pixel_elapsed = time.time() - pixel_check_start
|
||||
|
||||
try:
|
||||
|
||||
@@ -160,6 +160,16 @@ 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 "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(
|
||||
0.0, min(1.0, threshold)
|
||||
)
|
||||
else:
|
||||
analyser.shopping_redpacket_red_ratio_threshold = getattr(
|
||||
analyser, "shopping_redpacket_red_ratio_threshold", 0.15
|
||||
)
|
||||
|
||||
# 粉丝团等待/点击延迟配置
|
||||
if "fansclub_click_delay" in config:
|
||||
analyser.fansclub_click_delay = float(config["fansclub_click_delay"] or 0.6)
|
||||
|
||||
@@ -666,6 +666,10 @@ def main():
|
||||
fansclub_join_red_ratio_threshold_var = tk.DoubleVar(
|
||||
value=float(cfg.get("fansclub_join_red_ratio_threshold", 0.25) or 0.25)
|
||||
)
|
||||
# 购物红包背景红色占比阈值(0.0~1.0,默认0.15)
|
||||
shopping_redpacket_red_ratio_threshold_var = tk.DoubleVar(
|
||||
value=float(cfg.get("shopping_redpacket_red_ratio_threshold", 0.15) or 0.15)
|
||||
)
|
||||
|
||||
# 调试图像开关 & 清理相关变量
|
||||
debug_captures_enabled_var = tk.BooleanVar(
|
||||
@@ -1689,6 +1693,21 @@ def main():
|
||||
side=LEFT, padx=(6, 0)
|
||||
)
|
||||
|
||||
pixel_r3 = ttk.Frame(pixel_detect_box)
|
||||
pixel_r3.pack(fill=X, padx=10, pady=(0, 10))
|
||||
ttk.Label(pixel_r3, text="购物红包背景红色占比阈值:").pack(side=LEFT)
|
||||
ttk.Spinbox(
|
||||
pixel_r3,
|
||||
from_=0.0,
|
||||
to=1.0,
|
||||
increment=0.01,
|
||||
textvariable=shopping_redpacket_red_ratio_threshold_var,
|
||||
width=8,
|
||||
).pack(side=LEFT)
|
||||
ttk.Label(pixel_r3, text="(默认0.15,用于检测购物红包弹窗背景)").pack(
|
||||
side=LEFT, padx=(6, 0)
|
||||
)
|
||||
|
||||
# 标签页5:日志配置
|
||||
logging_tab = ttk.Frame(left_notebook)
|
||||
left_notebook.add(logging_tab, text="日志配置")
|
||||
@@ -2063,6 +2082,9 @@ def main():
|
||||
fansclub_join_red_ratio_threshold_var.set(
|
||||
float(cfg.get("fansclub_join_red_ratio_threshold", 0.25) or 0.25)
|
||||
)
|
||||
shopping_redpacket_red_ratio_threshold_var.set(
|
||||
float(cfg.get("shopping_redpacket_red_ratio_threshold", 0.15) or 0.15)
|
||||
)
|
||||
# 粉丝团等待/点击延迟配置
|
||||
fansclub_click_delay_var.set(float(cfg.get("fansclub_click_delay", 0.6) or 0.6))
|
||||
fansclub_auto_wait_var.set(
|
||||
@@ -2350,6 +2372,9 @@ def main():
|
||||
cfg2["fansclub_join_red_ratio_threshold"] = float(
|
||||
fansclub_join_red_ratio_threshold_var.get() or 0.25
|
||||
)
|
||||
cfg2["shopping_redpacket_red_ratio_threshold"] = float(
|
||||
shopping_redpacket_red_ratio_threshold_var.get() or 0.15
|
||||
)
|
||||
# 粉丝团等待/点击延迟配置
|
||||
cfg2["fansclub_click_delay"] = float(fansclub_click_delay_var.get() or 0.6)
|
||||
cfg2["fansclub_auto_join_wait_seconds"] = float(
|
||||
|
||||
Reference in new issue
Block a user