'commit'
This commit is contained in:
@@ -8,7 +8,7 @@ import uuid
|
||||
import uiautomator2 as u2
|
||||
|
||||
from Apps.XinDianTu.Kit import take_screenshot, detect_black_agree_button, detect_any_ad_close, \
|
||||
detect_bottom_close_circle
|
||||
detect_bottom_close_circle, is_background_dimmed
|
||||
from Config.Config import TEMP_IMAGE_DIR
|
||||
|
||||
# pip install adbutils
|
||||
@@ -33,6 +33,11 @@ async def check_and_close_ad(d):
|
||||
save_dir = TEMP_IMAGE_DIR
|
||||
screenshot_path = take_screenshot(d, image_uuid, save_dir=save_dir)
|
||||
logger.info(f"Step [广告检测截图] 耗时: {time.time() - t1:.4f}s")
|
||||
|
||||
# 1.1 特征预检:检测背景蒙板
|
||||
is_dimmed = is_background_dimmed(screenshot_path)
|
||||
if is_dimmed:
|
||||
logger.info("检测到背景变暗(蒙板),极大概率存在广告弹窗。")
|
||||
|
||||
# 2. 图形学检测方案 (Local CV)
|
||||
t_cv = time.time()
|
||||
@@ -55,7 +60,9 @@ async def check_and_close_ad(d):
|
||||
|
||||
if os.path.exists(template_dir):
|
||||
logger.info(f"正在尝试多模板匹配关闭按钮: {template_dir}")
|
||||
close_pos = detect_any_ad_close(screenshot_path, template_dir, debug_dir=save_dir)
|
||||
# 如果检测到蒙板,可以适当调低匹配阈值
|
||||
match_threshold = 0.6 if is_dimmed else 0.7
|
||||
close_pos = detect_ad_close_x_with_threshold(screenshot_path, template_dir, save_dir, match_threshold)
|
||||
|
||||
if close_pos:
|
||||
x, y = close_pos
|
||||
@@ -78,17 +85,27 @@ async def check_and_close_ad(d):
|
||||
os.remove(screenshot_path)
|
||||
return True
|
||||
|
||||
logger.info(f"本地图形学检测完成,未发现已知广告。耗时: {time.time() - t_cv:.4f}s")
|
||||
logger.info(f"本地图形学检测完成,未发现已知广告。")
|
||||
|
||||
# [优化] 用户指示:回退到大模型检查不靠谱且浪费。
|
||||
# 如果本地图形学方案(黑按钮、X关闭)都未命中,则直接认为无广告或已进入正常页面。
|
||||
|
||||
# 清理本地截图
|
||||
if os.path.exists(screenshot_path):
|
||||
os.remove(screenshot_path)
|
||||
|
||||
return False
|
||||
|
||||
def detect_ad_close_x_with_threshold(screenshot_path, template_dir, debug_dir, threshold):
|
||||
"""
|
||||
带自定义阈值的多模板匹配
|
||||
"""
|
||||
for filename in os.listdir(template_dir):
|
||||
if filename.startswith("ad_close") and filename.endswith(".jpg"):
|
||||
template_path = os.path.join(template_dir, filename)
|
||||
from Apps.XinDianTu.Kit import detect_ad_close_x
|
||||
pos = detect_ad_close_x(screenshot_path, template_path, debug_dir=debug_dir, threshold=threshold)
|
||||
if pos:
|
||||
return pos
|
||||
return None
|
||||
|
||||
|
||||
async def open_mini_program():
|
||||
"""
|
||||
|
||||
Reference in New Issue
Block a user