'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 SAFE_EXCLUDE_RATIO, BOTTOM_SAFE_EXCLUDE_RATIO
|
||||
from Apps.XinDianTu.Config.Setting import SAFE_EXCLUDE_RATIO, BOTTOM_SAFE_EXCLUDE_RATIO, MIN_CARD_HEIGHT_RATIO
|
||||
from Config.Config import TEMP_IMAGE_DIR
|
||||
|
||||
logging.basicConfig(level=logging.INFO, format="%(asctime)s - %(name)s - %(levelname)s - %(message)s")
|
||||
@@ -862,12 +862,21 @@ def crop_cards_from_image(img_path, output_dir=None, save_debug=True):
|
||||
max_h = max(heights)
|
||||
median_h = np.median(heights)
|
||||
|
||||
threshold_h = median_h * 0.80
|
||||
min_abs_h = h * MIN_CARD_HEIGHT_RATIO
|
||||
base_threshold = max(median_h * 0.90, min_abs_h)
|
||||
|
||||
for (y1, y2), card_h in zip(temp_valid_segments, heights):
|
||||
if card_h < threshold_h:
|
||||
center_y = (y1 + y2) / 2.0
|
||||
|
||||
local_threshold = base_threshold
|
||||
|
||||
if center_y > h * 0.70:
|
||||
local_threshold = median_h * 0.70
|
||||
|
||||
if card_h < local_threshold:
|
||||
logger.info(
|
||||
f" Filtering out segment Y={y1}-{y2} (H={card_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 "
|
||||
f"(Threshold={local_threshold:.1f}, center_y={center_y:.1f}).")
|
||||
else:
|
||||
final_cards.append((y1, y2, final_x1, final_x2))
|
||||
logger.info(f" Card: Y={y1}-{y2}, X={final_x1}-{final_x2}, H={card_h}")
|
||||
@@ -908,18 +917,24 @@ def crop_cards_from_image(img_path, output_dir=None, save_debug=True):
|
||||
# 准备 _vl.jpg (只画框,不画红点)
|
||||
vl_img = img.copy()
|
||||
|
||||
logger.info(f" Step [2.1/VL] 准备在 VL 图片上绘制 {len(final_cards)} 个场站的绿色方框...")
|
||||
logger.info(f" Step [2.1/VL] 准备在 VL 图片上绘制 {len(final_cards)} 个场站的绿色方框...")
|
||||
|
||||
for idx, (y1, y2, x1, x2) in enumerate(final_cards):
|
||||
PAD_TOP = 5
|
||||
draw_y1 = max(0, y1 - PAD_TOP)
|
||||
draw_y2 = y2
|
||||
|
||||
w_card = x2 - x1
|
||||
h_card = draw_y2 - draw_y1
|
||||
|
||||
click_x = int((x1 + x2) / 2)
|
||||
click_y = int((draw_y1 + draw_y2) / 2)
|
||||
for idx, (y1, y2, x1, x2) in enumerate(final_cards):
|
||||
segment_height = y2 - y1
|
||||
pad_top = int(segment_height * 0.20)
|
||||
if pad_top < 10:
|
||||
pad_top = 10
|
||||
if pad_top > 60:
|
||||
pad_top = 60
|
||||
|
||||
draw_y1 = max(0, y1 - pad_top)
|
||||
draw_y2 = y2
|
||||
|
||||
w_card = x2 - x1
|
||||
h_card = draw_y2 - draw_y1
|
||||
|
||||
click_x = int((x1 + x2) / 2)
|
||||
click_y = int((draw_y1 + draw_y2) / 2)
|
||||
|
||||
# [修改] 不再保存单张子图,只记录元数据
|
||||
# card = img[y1:y2, x1:x2]
|
||||
|
||||
Reference in New Issue
Block a user