'commit'
This commit is contained in:
@@ -417,6 +417,38 @@ def clear_temp_dir(save_dir=None):
|
||||
except Exception as e:
|
||||
logger.error(f"Error deleting file {file_path}: {e}")
|
||||
|
||||
from Util.EasyOcrKit import get_easyocr_reader
|
||||
|
||||
# 预加载 EasyOCR Reader (单例模式)
|
||||
def get_ocr_reader():
|
||||
return get_easyocr_reader(gpu=True)
|
||||
|
||||
def detect_price_info_container_cv(image_path):
|
||||
"""
|
||||
使用 OCR 精准定位详情页中的“全部时段”文本。
|
||||
返回: [x1, y1, x2, y2] 归一化坐标,如果未找到则返回 None
|
||||
"""
|
||||
img = read_image(image_path)
|
||||
if img is None:
|
||||
return None
|
||||
h, w = img.shape[:2]
|
||||
|
||||
try:
|
||||
reader = get_ocr_reader()
|
||||
# 使用封装后的方法查找文本
|
||||
found = reader.find_text_position(img, '全部时段')
|
||||
|
||||
if found:
|
||||
text, quad, prob = found
|
||||
# 使用封装后的方法计算归一化矩形
|
||||
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}")
|
||||
|
||||
return None
|
||||
|
||||
def setup_logger(name, log_file=None, clear_old_log=False):
|
||||
"""
|
||||
配置日志,支持同时输出到控制台和文件。
|
||||
|
||||
Reference in New Issue
Block a user