'commit'
This commit is contained in:
@@ -204,8 +204,8 @@ def detect_rabbit_ad_close(image_path, debug_dir=None):
|
||||
cX = int(M["m10"] / M["m00"]) + roi_x1
|
||||
cY = int(M["m01"] / M["m00"]) + roi_y1
|
||||
|
||||
norm_x = int(cX / w * 1000)
|
||||
norm_y = int(cY / h * 1000)
|
||||
norm_x = cX / w
|
||||
norm_y = cY / h
|
||||
|
||||
# 避免重复
|
||||
if not any(abs(cX - c[0]) < 15 and abs(cY - c[1]) < 15 for c in candidates):
|
||||
@@ -220,17 +220,23 @@ def detect_rabbit_ad_close(image_path, debug_dir=None):
|
||||
has_x = c[5]
|
||||
# 基础分:如果有 X,大幅加分
|
||||
score = 1000 if has_x else 0
|
||||
# 距离分:越靠近预期的 (93, 830) 分越高
|
||||
dist = np.sqrt((c[3] - 93)**2 + (c[4] - 830)**2)
|
||||
score -= dist * 2
|
||||
# 距离分:越靠近预期的 (0.094, 0.830) 分越高
|
||||
dist = np.sqrt((c[3] - 0.094)**2 + (c[4] - 0.830)**2)
|
||||
score -= dist * 2000 # 归一化后距离变小,需加大权重
|
||||
# 面积分:理想面积在 500-1500 之间
|
||||
if 500 < c[2] < 1500: score += 200
|
||||
return score
|
||||
|
||||
candidates.sort(key=score_candidate, reverse=True)
|
||||
best = candidates[0]
|
||||
best_score = score_candidate(best)
|
||||
|
||||
logger.info(f"CV detected rabbit ad close button at Norm({best[3]}, {best[4]}) with score {score_candidate(best):.2f}")
|
||||
logger.info(f"CV detected rabbit ad close button at Norm({best[3]:.3f}, {best[4]:.3f}) with score {best_score:.2f}")
|
||||
|
||||
# 【优化】如果得分太低 (低于 850),说明误判概率较大,不予返回
|
||||
if best_score < 850:
|
||||
logger.info(f"Score {best_score:.2f} is below threshold 850, ignoring candidate.")
|
||||
return None
|
||||
|
||||
if debug_dir:
|
||||
os.makedirs(debug_dir, exist_ok=True)
|
||||
@@ -749,13 +755,19 @@ def crop_cards_from_image(img_path, output_dir=None, save_debug=True):
|
||||
# 使用 Median 比 Max 更稳健,避免被单个超高卡片(如广告)带偏
|
||||
threshold_h = median_h * 0.70
|
||||
|
||||
for (y1, y2), h in zip(temp_valid_segments, heights):
|
||||
if h < threshold_h:
|
||||
for (y1, y2), card_h in zip(temp_valid_segments, heights):
|
||||
# 【优化】过滤顶部非场站区域 (例如会员图标、搜索栏等)
|
||||
# 场站列表通常在屏幕 35% 高度以后
|
||||
if y1 / h < 0.35:
|
||||
logger.info(f" Filtering out segment Y={y1}-{y2} because it's too high up (Top {y1/h:.2f} < 0.35).")
|
||||
continue
|
||||
|
||||
if card_h < threshold_h:
|
||||
logger.info(
|
||||
f" Filtering out segment Y={y1}-{y2} (H={h}) because it's too short (Threshold={threshold_h:.1f}).")
|
||||
f" Filtering out segment Y={y1}-{y2} (H={card_h}) because it's too short (Threshold={threshold_h:.1f}).")
|
||||
else:
|
||||
final_cards.append((y1, y2, final_x1, final_x2))
|
||||
logger.info(f" Card: Y={y1}-{y2}, X={final_x1}-{final_x2}, H={h}")
|
||||
logger.info(f" Card: Y={y1}-{y2}, X={final_x1}-{final_x2}, H={card_h}")
|
||||
|
||||
# 4. 保存结果
|
||||
if output_dir is None:
|
||||
@@ -812,6 +824,12 @@ def crop_cards_from_image(img_path, output_dir=None, save_debug=True):
|
||||
card_info = {
|
||||
"id": idx + 1,
|
||||
"rect": [x1, y1, x2, y2],
|
||||
"bounds_norm": {
|
||||
"left": x1 / w,
|
||||
"top": y1 / h,
|
||||
"right": x2 / w,
|
||||
"bottom": y2 / h
|
||||
},
|
||||
"click_point": [click_x, click_y]
|
||||
}
|
||||
json_data["cards"].append(card_info)
|
||||
|
||||
Reference in New Issue
Block a user