修改indoor警报
This commit is contained in:
@@ -96,31 +96,31 @@ class PrisonerDoorDetector:
|
||||
return (True, roi_name)
|
||||
return (False, "outside")
|
||||
|
||||
def push_alert(self, camera_id, track_id, lost_roi, last_cxcy, timestamp):
|
||||
"""报警推送:带频率限制,携带消失ROI、最后中心点坐标"""
|
||||
current_time = time.time()
|
||||
if current_time - self.last_alert_time < ALERT_PUSH_INTERVAL:
|
||||
return False
|
||||
# 构造报警信息(可根据平台要求扩展字段)
|
||||
alert_info = {
|
||||
"camera_id": camera_id,
|
||||
"alert_type": "prisoner_cx_disappear_in_roi",
|
||||
"prisoner_track_id": track_id,
|
||||
"disappear_roi": lost_roi,
|
||||
"last_cx": round(last_cxcy[0], 2),
|
||||
"last_cy": round(last_cxcy[1], 2),
|
||||
"timestamp": timestamp,
|
||||
"details": f"犯人框中心点在{lost_roi}区域内消失,触发报警"
|
||||
}
|
||||
# 推送报警请求
|
||||
try:
|
||||
requests.post(ALERT_PUSH_URL, json=alert_info, timeout=3)
|
||||
print(f"[报警成功] {alert_info}")
|
||||
self.last_alert_time = current_time
|
||||
return True
|
||||
except Exception as e:
|
||||
print(f"[报警失败] 原因:{str(e)}")
|
||||
return False
|
||||
# def push_alert(self, camera_id, track_id, lost_roi, last_cxcy, timestamp):
|
||||
# """报警推送:带频率限制,携带消失ROI、最后中心点坐标"""
|
||||
# current_time = time.time()
|
||||
# if current_time - self.last_alert_time < ALERT_PUSH_INTERVAL:
|
||||
# return False
|
||||
# # 构造报警信息(可根据平台要求扩展字段)
|
||||
# alert_info = {
|
||||
# "camera_id": camera_id,
|
||||
# "alert_type": "prisoner_cx_disappear_in_roi",
|
||||
# "prisoner_track_id": track_id,
|
||||
# "disappear_roi": lost_roi,
|
||||
# "last_cx": round(last_cxcy[0], 2),
|
||||
# "last_cy": round(last_cxcy[1], 2),
|
||||
# "timestamp": timestamp,
|
||||
# "details": f"犯人框中心点在{lost_roi}区域内消失,触发报警"
|
||||
# }
|
||||
# # 推送报警请求
|
||||
# try:
|
||||
# requests.post(ALERT_PUSH_URL, json=alert_info, timeout=3)
|
||||
# print(f"[报警成功] {alert_info}")
|
||||
# self.last_alert_time = current_time
|
||||
# return True
|
||||
# except Exception as e:
|
||||
# print(f"[报警失败] 原因:{str(e)}")
|
||||
# return False
|
||||
|
||||
def process_frame(self, frame, camera_id: int, timestamp: float) -> dict:
|
||||
"""
|
||||
@@ -207,18 +207,18 @@ class PrisonerDoorDetector:
|
||||
track_info["lost_frames"] += 1 # 累计消失帧数
|
||||
# 消失帧数达到阈值,触发报警
|
||||
if track_info["lost_frames"] >= ROI_LOST_FRAMES_THRESH:
|
||||
self.push_alert(
|
||||
camera_id=camera_id,
|
||||
track_id=track_id,
|
||||
lost_roi=track_info["lost_roi"],
|
||||
last_cxcy=track_info["last_cxcy"],
|
||||
timestamp=timestamp
|
||||
)
|
||||
# self.push_alert(
|
||||
# camera_id=camera_id,
|
||||
# track_id=track_id,
|
||||
# lost_roi=track_info["lost_roi"],
|
||||
# last_cxcy=track_info["last_cxcy"],
|
||||
# timestamp=timestamp
|
||||
# )
|
||||
# 记录本帧报警信息
|
||||
current_frame_alerts.append({
|
||||
"time": timestamp,
|
||||
"camera_id": camera_id,
|
||||
"action": "prisoner_cx_disappear_in_door",
|
||||
"action": "Indoor Violation",
|
||||
"prisoner_track_id": track_id,
|
||||
"disappear_roi": track_info["lost_roi"],
|
||||
"last_cx": round(track_info["last_cxcy"][0], 2),
|
||||
|
||||
Reference in New Issue
Block a user