|
@@ -14,8 +14,9 @@ video_path = r"E:\desktop_file\速度标定\run.mp4"
|
|
|
cap = cv2.VideoCapture(video_path)
|
|
|
|
|
|
|
|
|
-frame_buffer = deque(maxlen=200)
|
|
|
-
|
|
|
+frame_buffer = deque(maxlen=100)
|
|
|
+
|
|
|
+active_tasks = []
|
|
|
|
|
|
track_history = defaultdict(lambda: [])
|
|
|
|
|
@@ -82,7 +83,7 @@ frame_width = int(cap.get(cv2.CAP_PROP_FRAME_WIDTH))
|
|
|
frame_height = int(cap.get(cv2.CAP_PROP_FRAME_HEIGHT))
|
|
|
out = cv2.VideoWriter(output_file, fourcc, fps, (frame_width, frame_height))
|
|
|
|
|
|
-speed_threshold = 30
|
|
|
+speed_threshold = 20
|
|
|
high_velocity_count_threshold = 20
|
|
|
|
|
|
|
|
@@ -97,6 +98,18 @@ while cap.isOpened():
|
|
|
|
|
|
frame_buffer.append(frame.copy())
|
|
|
|
|
|
+
|
|
|
+ for i in reversed(range(len(active_tasks))):
|
|
|
+ pre_buffer, post_buffer, frames_left, trigger_time = active_tasks[i]
|
|
|
+ post_buffer.append(frame.copy())
|
|
|
+ frames_left -= 1
|
|
|
+ if frames_left <= 0:
|
|
|
+ combined = pre_buffer + list(post_buffer)
|
|
|
+ save_high_speed_video(combined, trigger_time)
|
|
|
+ del active_tasks[i]
|
|
|
+ else:
|
|
|
+ active_tasks[i] = (pre_buffer, post_buffer, frames_left, trigger_time)
|
|
|
+
|
|
|
|
|
|
results = model.track(frame, persist=True, classes=0, conf=0.6)
|
|
|
|
|
@@ -165,6 +178,12 @@ while cap.isOpened():
|
|
|
|
|
|
|
|
|
|
|
|
+
|
|
|
+ pre_buffer = list(frame_buffer)
|
|
|
+ post_buffer = deque(maxlen=100)
|
|
|
+ trigger_time = datetime.datetime.now()
|
|
|
+ active_tasks.append((pre_buffer, post_buffer, 100, trigger_time))
|
|
|
+
|
|
|
|
|
|
instantaneous_velocities[track_id] = deque(
|
|
|
[velocity for velocity in instantaneous_velocities[track_id] if velocity <= speed_threshold],
|