Overview

Buffer module for temporal frame and results management. This module provides a rolling window buffer that collects frames and their corresponding detection results, enabling temporal context for downstream processing. The buffer implements a delay-based temporal processing approach, returning the middle frame once the buffer is full, which provides both past and future context for advanced computer vision operations like motion smoothing, temporal interpolation, and trajectory analysis. The Buffer class implements a temporal processing strategy using a rolling window approach that maintains a fixed-size collection of frames and their corresponding detection results. It employs a delay-based algorithm that returns the middle frame once the buffer reaches capacity, providing both historical and future context for advanced computer vision operations. The buffer is particularly useful for temporal smoothing, motion analysis, trajectory prediction, and any processing that benefits from knowing both past and future states. It automatically handles buffer management, frame synchronization, and provides convenient access to temporal context. Attributes: buffer_size (int): Number of frames to buffer (should be odd for clean middle) frame_buffer (List[np.ndarray]): List storing the buffered frames results_buffer (List): List storing the buffered results is_full (bool): Whether the buffer has reached capacity

Class Overview

The Buffer class provides structured data management for buffer operations.

Examples

import cv2
import pixelflow as pf
from ultralytics import YOLO

# Setup model and buffer
model = YOLO("yolo11l.pt")
buffer = pf.Buffer(frames=5)  # 2 past + 1 current + 2 future

# Process video with temporal context
cap = cv2.VideoCapture("video.mp4")
while True:

Notes

  • Buffer introduces a delay equal to buffer_size // 2 frames
  • Odd buffer sizes provide clean middle frame alignment
  • Even buffer sizes will still work but with slight offset
  • Memory usage scales linearly with buffer size and frame resolution
  • All frames are copied to prevent external modifications
  • Memory usage: buffer_size * frame_size * channels bytes
  • Frame copying adds ~10-20% overhead for typical resolutions
  • Buffer operations are O(1) for update, O(n) for full access
  • Consider buffer size vs available memory for high-resolution video