项目文件夹

文件
wehub-resource-sync 39a086b41b
Build Windows CPU / build (push) Has been cancelled
Build Windows CUDA 10.2 / build (push) Has been cancelled
Build Windows CUDA 11.8 / build (push) Has been cancelled
Build Windows CUDA 12.6 / build (push) Has been cancelled
Build Windows DirectML / build (push) Has been cancelled
chore: import upstream snapshot with attribution
2026-07-13 13:08:08 +08:00

38 行
1.2 KiB
Python

此文件含有模棱两可的 Unicode 字符
此文件含有可能会与其他字符混淆的 Unicode 字符。 如果您是想特意这样的,可以安全地忽略该警告。 使用 Escape 按钮显示他们。
from backend.tools.paddle_model_config import PaddleModelConfig
from backend.tools.hardware_accelerator import HardwareAccelerator
import numpy as np
try:
from paddleocr import TextDetection
except ImportError:
TextDetection = None
class SubtitleDetect:
"""
文本框检测类,用于检测视频帧中是否存在文本框
"""
def __init__(self):
hardware_accelerator = HardwareAccelerator.instance()
model_config = PaddleModelConfig(hardware_accelerator)
# 使用 TextDetection 公开 APIPaddleOCR 3.x
kwargs = {'model_dir': model_config.DET_MODEL_PATH}
if model_config.DET_MODEL_NAME:
kwargs['model_name'] = model_config.DET_MODEL_NAME
self.text_detector = TextDetection(**kwargs)
def detect_subtitle(self, img):
"""
检测图像中的文本框
:param img: 输入图像
:return: (dt_boxes, elapse) dt_boxes为numpy数组,elapse为耗时
"""
results = list(self.text_detector.predict(img))
if not results:
return np.array([]), 0
res = results[0]
dt_polys = res.get('dt_polys', np.array([]))
return dt_polys, 0