优化ocr检测时间,加载默认模型

This commit is contained in:
2025-10-10 11:35:37 +08:00
parent 8c2e497163
commit 6cdb1e3d7d
5 changed files with 250 additions and 111 deletions

View File

@ -44,7 +44,6 @@ def save_db(model_type, client_ip, result):
def detectFrame(client_ip, frame):
# YOLO检测
yolo_flag, yolo_result = yoloDetect(frame, float(BUSINESS_CONFIG["yolo_conf"]))
if yolo_flag:
@ -103,36 +102,11 @@ def danger_handler(client_ip):
json_data=json.dumps(lock_msg)
)
)
# 增加危险记录次数
increment_alarm_count_by_ip(client_ip)
# 更新设备状态为未处理
update_is_need_handler_by_client_ip(client_ip, 1)
def extract_prohibited_words(ocr_result: str) -> str:
"""
从多文本块的ocr_result中提取所有违禁词去重后用逗号拼接
适配格式:多个"文本: ... 包含违禁词: ...;"片段
"""
# 用正则匹配所有"包含违禁词: ...;"的片段(非贪婪匹配到分号)
# 匹配规则:"包含违禁词: "后面的内容,直到遇到";"结束
pattern = r"包含违禁词: (.*?);"
all_prohibited_segments = re.findall(pattern, ocr_result, re.DOTALL)
all_words = []
for segment in all_prohibited_segments:
# 去除每个片段中的置信度信息(如"(置信度: 1.00)"
cleaned = re.sub(r"\s*\([^)]*\)", "", segment.strip())
# 分割词语并过滤空值
words = [word.strip() for word in cleaned.split(",") if word.strip()]
all_words.extend(words)
# 去重后用逗号拼接
unique_words = list(set(all_words))
return ",".join(unique_words)
def extract_face_names(face_result: str) -> str:
pattern = r"匹配: (.*?) \("
all_names = re.findall(pattern, face_result)