Class HistoryFrame
- Assembly
- VisioForge.Core.dll
History frame, contains 3 previous frames.
public class HistoryFrame : IDisposableInheritance
Implements
Inherited Members
Remarks
The HistoryFrame class is used in video processing algorithms that require temporal information, such as motion detection, deinterlacing, and noise reduction. It maintains a rolling buffer of the three most recent frames (Frame0, Frame1, Frame2) plus a copy of the current frame.
Frame organization: - Frame0: Most recent frame (current - 1) - Frame1: Previous frame (current - 2) - Frame2: Oldest frame (current - 3) - CurrentFrameCopy: Copy of the current frame being processed
This class uses unmanaged memory allocation for performance reasons, as video frames can be large and frequent allocations would impact performance. The class implements IDisposable to ensure proper cleanup of unmanaged resources.
Constructors
HistoryFrame(BaseContext)
Initializes a new instance of the VisioForge.Core.Types.FastImageProcessing.HistoryFrame class.
public HistoryFrame(BaseContext context)Parameters
contextBaseContext-
The context.
Fields
CurrentFrameCopy
The current frame copy.
public nint CurrentFrameCopyField Value
Remarks
A separate copy of the current frame being processed. This allows algorithms to modify the current frame while preserving the original for history tracking.
Frame0
Frame 0 - Most recent historical frame (current - 1).
public nint Frame0Field Value
Remarks
Contains the frame data from one frame ago. This is typically used as the primary reference frame for motion detection and temporal filtering algorithms.
Frame1
Frame 1 - Previous historical frame (current - 2).
public nint Frame1Field Value
Remarks
Contains the frame data from two frames ago. Used for multi-frame analysis and advanced temporal processing algorithms.
Frame2
Frame 2 - Oldest historical frame (current - 3).
public nint Frame2Field Value
Remarks
Contains the frame data from three frames ago. Provides extended temporal context for algorithms requiring longer history windows.
Methods
Allocate(int, nint)
Allocates frames.
public void Allocate(int size, nint frame)Parameters
sizeint-
Frame size in bytes. Calculate as: width * height * bytes_per_pixel. For example, a 1920x1080 BGRA frame would be 1920 * 1080 * 4 = 8,294,400 bytes.
framenint-
Pointer to the initial frame data used to populate all history frames. This prevents undefined behavior when accessing history before enough frames have been processed.
Remarks
This method must be called before using the history frame. It allocates unmanaged memory for all frame buffers and initializes them with the provided frame data. This initialization strategy prevents artifacts in temporal algorithms during startup.
Exceptions
- OutOfMemoryException
-
Thrown if there is insufficient memory to allocate the frame buffers.
Clear()
Clears frames.
public void Clear()Dispose(bool)
Releases unmanaged resources used by this instance and, optionally, managed resources.
protected virtual void Dispose(bool disposing)Parameters
disposingbool-
trueto release both managed and unmanaged resources;falseto release only unmanaged resources.
Dispose()
Releases all unmanaged frame buffers held by this instance.
public void Dispose()Fill(nint, int)
Fills frames.
public void Fill(nint frame, int frameSize)Parameters
framenint-
Pointer to the new frame data to be added to the history.
frameSizeint-
Frame size in bytes. Must match the size used in Allocate().
Examples
// Process video frames with history
foreach (var currentFrame in videoStream)
{
// Update history
history.Fill(currentFrame, frameSize);
// Now you can access:
// - currentFrame: The frame being processed
// - history.Frame0: Previous frame (t-1)
// - history.Frame1: Frame before that (t-2)
// - history.Frame2: Oldest frame (t-3)
}
Remarks
Updates the frame history by shifting frames: - Frame2 receives data from Frame1 (becomes oldest) - Frame1 receives data from Frame0 - Frame0 receives the new frame data (becomes most recent)
This creates a rolling buffer where Frame0 always contains the most recent historical frame, and Frame2 contains the oldest. The current frame parameter is not stored directly but can be copied to CurrentFrameCopy if needed.
~HistoryFrame()
Finalizes an instance of the VisioForge.Core.Types.FastImageProcessing.HistoryFrame class. Releases unmanaged resources.
protected ~HistoryFrame()