'commit'
This commit is contained in:
@@ -4,7 +4,7 @@ import cv2
|
||||
import numpy as np
|
||||
import time
|
||||
import hashlib
|
||||
from Apps.XinDianTu.Config.Setting import BOTTOM_SAFE_EXCLUDE_RATIO
|
||||
from Apps.XinDianTu.Config.Setting import SAFE_EXCLUDE_RATIO, BOTTOM_SAFE_EXCLUDE_RATIO
|
||||
from Config.Config import TEMP_IMAGE_DIR
|
||||
|
||||
logging.basicConfig(level=logging.INFO, format="%(asctime)s - %(name)s - %(levelname)s - %(message)s")
|
||||
@@ -748,26 +748,7 @@ def crop_cards_from_image(img_path, output_dir=None, save_debug=True):
|
||||
|
||||
logger.info(f" Found {len(groups)} segment groups.")
|
||||
|
||||
# Select the Target Group
|
||||
# Strategy: Select the LAST group that has at least one 'substantial' segment (H > 150).
|
||||
# This assumes the Station List is the main content and usually at the bottom (scrolling area).
|
||||
target_group = []
|
||||
for g in reversed(groups):
|
||||
# Check if group has substantial content
|
||||
has_content = False
|
||||
for (y1, y2) in g:
|
||||
if (y2 - y1) > 150:
|
||||
has_content = True
|
||||
break
|
||||
|
||||
if has_content:
|
||||
target_group = g
|
||||
break
|
||||
|
||||
if not target_group and segments:
|
||||
# Fallback to all segments if no substantial group found
|
||||
target_group = segments
|
||||
|
||||
target_group = segments
|
||||
logger.info(f" Selected group with {len(target_group)} segments.")
|
||||
|
||||
# 2. 确定每个卡片的左右边界 (Width Refinement)
|
||||
@@ -881,10 +862,7 @@ def crop_cards_from_image(img_path, output_dir=None, save_debug=True):
|
||||
max_h = max(heights)
|
||||
median_h = np.median(heights)
|
||||
|
||||
# 策略:如果高度差异较大,丢弃过小的卡片
|
||||
# 阈值设定为 Median 的 75% (允许一定程度的偏差,如 220 vs 258 是允许的,但 150 vs 250 应被过滤)
|
||||
# 使用 Median 比 Max 更稳健,避免被单个超高卡片(如广告)带偏
|
||||
threshold_h = median_h * 0.70
|
||||
threshold_h = median_h * 0.80
|
||||
|
||||
for (y1, y2), card_h in zip(temp_valid_segments, heights):
|
||||
if card_h < threshold_h:
|
||||
@@ -914,6 +892,19 @@ def crop_cards_from_image(img_path, output_dir=None, save_debug=True):
|
||||
"cards": []
|
||||
}
|
||||
|
||||
# 顶部安全过滤:丢弃中心落在 SAFE_EXCLUDE_RATIO 以上区域的卡片
|
||||
filtered_cards = []
|
||||
for y1, y2, x1, x2 in final_cards:
|
||||
center_y = (y1 + y2) / 2.0
|
||||
if center_y < h * SAFE_EXCLUDE_RATIO:
|
||||
logger.info(
|
||||
f" Dropping card Y={y1}-{y2} (center={center_y:.1f}) "
|
||||
f"because it is within top safe area ({SAFE_EXCLUDE_RATIO*100:.0f}%)."
|
||||
)
|
||||
continue
|
||||
filtered_cards.append((y1, y2, x1, x2))
|
||||
final_cards = filtered_cards
|
||||
|
||||
# 准备 _vl.jpg (只画框,不画红点)
|
||||
vl_img = img.copy()
|
||||
|
||||
|
||||
Reference in New Issue
Block a user