indoor_biz增加帧回溯(未测试)
This commit is contained in:
@@ -3,6 +3,8 @@ import numpy as np
|
||||
import time
|
||||
# import requests
|
||||
from collections import deque
|
||||
|
||||
from biz.base_detector import BaseDetector
|
||||
from biz.base_frame_processor import BaseFrameProcessorWorker
|
||||
from algorithm.common.npu_yolo_onnx_person_car_phone import YOLOv8_ONNX
|
||||
from yolox.tracker.byte_tracker import BYTETracker
|
||||
@@ -30,8 +32,9 @@ DEFAULT_DOOR_ROIS = {
|
||||
}
|
||||
|
||||
# ==================================================================================
|
||||
class PrisonerDoorDetector:
|
||||
class PrisonerDoorDetector(BaseDetector):
|
||||
def __init__(self, params=None):
|
||||
super().__init__()
|
||||
self.params = params or {}
|
||||
|
||||
# 0. 从params解析ROI配置,无则使用默认值
|
||||
@@ -80,6 +83,11 @@ class PrisonerDoorDetector:
|
||||
# 距离阈值(用于匹配检测框和已有目标)
|
||||
self.distance_threshold = 100 # 像素距离
|
||||
|
||||
buffer_seconds = 3 # 最大回溯3秒
|
||||
self.init_frame_buffer(buffer_seconds, RTSP_FPS)
|
||||
self.detect_rollback_time = 0.9 # 警报帧回溯时间(秒)
|
||||
|
||||
|
||||
def compute_center_distance(self, box1, box2):
|
||||
"""计算两个框中心点的欧氏距离"""
|
||||
cx1 = (box1[0] + box1[2]) / 2
|
||||
@@ -391,11 +399,13 @@ class PrisonerDoorDetector:
|
||||
# timestamp=timestamp,
|
||||
# entry_frame=entry_frame
|
||||
# )
|
||||
alert_frame = self.find_target_frame(timestamp - self.detect_rollback_time)
|
||||
|
||||
current_frame_alerts.append({
|
||||
"time": timestamp,
|
||||
"camera_id": camera_id,
|
||||
"action": "Indoor Violation",
|
||||
'image': alert_frame,
|
||||
"prisoner_track_id": target_id,
|
||||
"disappear_roi": target_info['current_roi'],
|
||||
"last_cx": round(target_info['last_cxcy'][0], 2),
|
||||
@@ -464,6 +474,8 @@ class PrisonerDoorDetector:
|
||||
(20, self.frame_height - 50),
|
||||
cv2.FONT_HERSHEY_SIMPLEX, 0.7, (255, 255, 0), 2)
|
||||
|
||||
self.append_frame(frame, timestamp)
|
||||
|
||||
return {"image": frame, "alerts": current_frame_alerts}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user