新增将监狱带出记录写进数据库

This commit is contained in:
zqc
2026-01-09 15:22:43 +08:00
parent 9f1ef55a6a
commit 18efe72b2c
3 changed files with 339 additions and 0 deletions

View File

@@ -25,6 +25,15 @@ try:
except Exception as e:
print(f"[WARN] 无法导入人脸识别算法: {e}")
# 导入数据库相关模块
try:
from services.sur_alert_record_service import SurAlertRecordService
from database.connection import db_manager
from models.sur_alert_record import AlertType
print("[INFO] 成功导入数据库模块")
except Exception as e:
print(f"[WARN] 无法导入数据库模块: {e}")
# -------------------------- Kadian 检测相关导入 --------------------------
from npu_yolo_onnx_person_car_phone import YOLOv8_ONNX # 主检测模型(人/车/后备箱/手机)
@@ -602,6 +611,19 @@ class FrameProcessorWorker(threading.Thread):
if result['has_passed']:
print(f"[INFO] 犯人带出: {result['passed_person_id']}")
# 插入数据库告警记录
try:
with db_manager.get_session() as db:
alert_service = SurAlertRecordService(db)
alert_service.create_alert_record(
alert_type=AlertType.PRISONER_OUT,
person_id=int(result['passed_person_id']),
camera_id=cam_id
)
# print(f"[INFO] 告警记录已插入数据库: person_id={result['passed_person_id']}")
except Exception as e:
print(f"[ERROR] 插入告警记录失败: {e}")
# 记录当前帧人脸告警信息
current_face_alert = {
"person_name": result['passed_person_id'],