This commit is contained in:
HuangHai
2026-01-15 10:14:44 +08:00
parent ccac3e889c
commit 23dfa433b0
6 changed files with 96 additions and 58 deletions

View File

@@ -161,7 +161,7 @@ def get_ocr_reader():
def detect_price_info_container_cv(image_path):
"""
使用 OCR 精准定位详情页中的“全部时段”文本。
使用 OCR 精准定位详情页中的价格入口文本(“全部时段”或“全天价格统一”)。
返回: [x1, y1, x2, y2] 归一化坐标,如果未找到则返回 None
"""
img = read_image(image_path)
@@ -169,17 +169,20 @@ def detect_price_info_container_cv(image_path):
return None
h, w = img.shape[:2]
keywords = ['全部时段', '全天价格统一']
try:
reader = get_ocr_reader()
# 使用封装后的方法查找文本
found = reader.find_text_position(img, '全部时段')
# 获取所有识别结果,避免重复 OCR
results = reader.read_text(img)
if found:
text, quad, prob = found
# 使用封装后的方法计算归一化矩形
res = reader.get_normalized_rect(quad, w, h)
print(f"[OCR识别] 找到文本: '{text}', 置信度: {prob:.4f}, 归一化坐标: {res}")
return res
for (quad, text, prob) in results:
# 检查是否包含任一关键字
if any(kw in text for kw in keywords) and prob >= 0.5:
# 使用封装后的方法计算归一化矩形
res = reader.get_normalized_rect(quad, w, h)
print(f"[OCR识别] 找到文本: '{text}', 置信度: {prob:.4f}, 归一化坐标: {res}")
return res
except Exception as e:
print(f"OCR 识别发生异常: {e}")