'commit'
This commit is contained in:
@@ -877,17 +877,57 @@ def crop_cards_from_image(img_path, output_dir=None, save_debug=True):
|
||||
# 准备 _vl.jpg (只画框,不画红点)
|
||||
vl_img = img.copy()
|
||||
|
||||
# 预先在整张图上标记“兔子广告潜在区域”的蓝色矩形,方便标定
|
||||
try:
|
||||
rabbit_x1 = int(w * 0.04)
|
||||
rabbit_x2 = int(w * 0.96)
|
||||
rabbit_y1 = int(h * 0.74)
|
||||
rabbit_y2 = int(h * 0.86)
|
||||
cv2.rectangle(debug_img, (rabbit_x1, rabbit_y1), (rabbit_x2, rabbit_y2), (255, 0, 0), 3)
|
||||
cv2.rectangle(vl_img, (rabbit_x1, rabbit_y1), (rabbit_x2, rabbit_y2), (255, 0, 0), 3)
|
||||
logger.info(f" 标记兔子广告蓝色区域: X={rabbit_x1}-{rabbit_x2}, Y={rabbit_y1}-{rabbit_y2}")
|
||||
except Exception as e:
|
||||
logger.warning(f"标记兔子广告蓝色区域失败: {e}")
|
||||
# 预先计算“列表浮动区域”的蓝色矩形坐标
|
||||
rabbit_x1 = int(w * 0.04)
|
||||
rabbit_x2 = int(w * 0.96)
|
||||
rabbit_y1 = int(h * 0.74)
|
||||
rabbit_y2 = int(h * 0.86)
|
||||
|
||||
# 在调试图上画出蓝色矩形
|
||||
try:
|
||||
cv2.rectangle(debug_img, (rabbit_x1, rabbit_y1), (rabbit_x2, rabbit_y2), (255, 0, 0), 3)
|
||||
cv2.rectangle(vl_img, (rabbit_x1, rabbit_y1), (rabbit_x2, rabbit_y2), (255, 0, 0), 3)
|
||||
logger.info(f" 标记列表浮动蓝色区域: X={rabbit_x1}-{rabbit_x2}, Y={rabbit_y1}-{rabbit_y2}")
|
||||
except Exception as e:
|
||||
logger.warning(f"标记兔子广告蓝色区域失败: {e}")
|
||||
|
||||
# 基于蓝色矩形过滤与列表浮动区域有交集的场站卡片
|
||||
if final_cards:
|
||||
logger.info(f" [蓝框过滤] 初始卡片数量: {len(final_cards)}")
|
||||
logger.info(
|
||||
f" [蓝框过滤] 蓝框坐标: X={rabbit_x1}-{rabbit_x2}, Y={rabbit_y1}-{rabbit_y2}"
|
||||
)
|
||||
|
||||
def _intersects(card):
|
||||
y1, y2, x1, x2 = card
|
||||
cx1, cy1, cx2, cy2 = x1, y1, x2, y2
|
||||
ix1 = max(cx1, rabbit_x1)
|
||||
iy1 = max(cy1, rabbit_y1)
|
||||
ix2 = min(cx2, rabbit_x2)
|
||||
iy2 = min(cy2, rabbit_y2)
|
||||
return ix1 < ix2 and iy1 < iy2
|
||||
|
||||
original_cards = list(final_cards)
|
||||
filtered_cards = []
|
||||
|
||||
for idx, card in enumerate(original_cards, start=1):
|
||||
y1, y2, x1, x2 = card
|
||||
if _intersects(card):
|
||||
logger.info(
|
||||
f" [蓝框过滤] 丢弃卡片#{idx}: X={x1}-{x2}, Y={y1}-{y2} (与蓝框有交集)"
|
||||
)
|
||||
else:
|
||||
logger.info(
|
||||
f" [蓝框过滤] 保留卡片#{idx}: X={x1}-{x2}, Y={y1}-{y2} (与蓝框无交集)"
|
||||
)
|
||||
filtered_cards.append(card)
|
||||
|
||||
logger.info(
|
||||
f" [蓝框过滤] 最终保留 {len(filtered_cards)} 个卡片, 丢弃 {len(original_cards) - len(filtered_cards)} 个"
|
||||
)
|
||||
final_cards = filtered_cards
|
||||
else:
|
||||
logger.info(" [蓝框过滤] 没有可过滤的卡片。")
|
||||
|
||||
logger.info(f" Step [2.1/VL] 准备在 VL 图片上绘制 {len(final_cards)} 个场站的绿色方框...")
|
||||
|
||||
|
||||
@@ -51,25 +51,20 @@ async def check_and_close_ad(d):
|
||||
if ad_result:
|
||||
x, y = ad_result["x"], ad_result["y"]
|
||||
ad_type = ad_result.get("ad_type")
|
||||
|
||||
logger.info(f"检测到广告关闭按钮: ({x}, {y}) [Type: {ad_type}]")
|
||||
|
||||
|
||||
# 根据新的策略:完全静默忽略 rabbit 类型广告
|
||||
if ad_type == "rabbit":
|
||||
logger.info(">>> 检测到兔子广告。使用模型返回的坐标关闭...")
|
||||
try:
|
||||
d.click(x, y)
|
||||
await asyncio.sleep(1.5)
|
||||
except Exception as ex:
|
||||
logger.error(f">>> 坐标点击兔子广告关闭按钮异常: {ex}")
|
||||
|
||||
if os.path.exists(screenshot_path): os.remove(screenshot_path)
|
||||
if os.path.exists(screenshot_path):
|
||||
os.remove(screenshot_path)
|
||||
return True
|
||||
else:
|
||||
logger.info(f">>> 正在点击关闭非兔子广告 ({ad_type})...")
|
||||
logger.info(f"检测到广告关闭按钮: ({x}, {y}) [Type: {ad_type}]")
|
||||
logger.info(f">>> 正在点击关闭非 rabbit 广告 ({ad_type})...")
|
||||
d.click(x, y)
|
||||
await asyncio.sleep(2.0) # 等待关闭动画
|
||||
|
||||
if os.path.exists(screenshot_path): os.remove(screenshot_path)
|
||||
if os.path.exists(screenshot_path):
|
||||
os.remove(screenshot_path)
|
||||
# 继续下一轮循环,检查是否还有其他广告
|
||||
continue
|
||||
else:
|
||||
|
||||
@@ -157,19 +157,10 @@ class ReadImageKit:
|
||||
norm_x, norm_y = norm_point
|
||||
ad_type = result.get("ad_type", "unknown")
|
||||
|
||||
if ad_type == "rabbit":
|
||||
ratio_x = norm_x / 1000.0
|
||||
if ratio_x < 0.3:
|
||||
x = int(primary_width * 0.094)
|
||||
y = int(primary_height * 0.83)
|
||||
logger.info("采用左侧兔子广告固定坐标关闭按钮 (0.094W, 0.83H)")
|
||||
else:
|
||||
x = int(primary_width * 0.88)
|
||||
y = int(primary_height * 0.83)
|
||||
logger.info("采用右侧浮动广告固定坐标关闭按钮 (0.88W, 0.83H)")
|
||||
else:
|
||||
x = int(norm_x / 1000 * primary_width)
|
||||
y = int(norm_y / 1000 * primary_height)
|
||||
# 统一采用模型返回的归一化坐标计算关闭按钮位置,
|
||||
# 不再对 rabbit 类型做特殊日志或固定坐标处理
|
||||
x = int(norm_x / 1000 * primary_width)
|
||||
y = int(norm_y / 1000 * primary_height)
|
||||
|
||||
try:
|
||||
os.makedirs(TEMP_IMAGE_DIR, exist_ok=True)
|
||||
|
||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Reference in New Issue
Block a user