Class HistoryFrame
- Assembly
- VisioForge.Core.dll
History frame, contains the 3 most recent 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, newest first, as VisioForge.Core.Types.FastImageProcessing.HistoryFrame.Fill(System.IntPtr,System.Int32) pushes them: - Frame0: the frame pushed last - Frame1: the one pushed before it - Frame2: the oldest - CurrentFrameCopy: Copy of the current frame being processed
Which of them is the current frame depends on whether the caller pushes it before or after processing it; each FastImageProcessing method taking a HistoryFrame says which frame it reads as which.
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 - the frame pushed last.
public nint Frame0Field Value
Remarks
The newest frame: the current one when the caller pushes it before processing, the one before otherwise. This is typically used as the primary reference frame for motion detection and temporal filtering algorithms.
Frame1
Frame 1 - the frame pushed before Frame0.
public nint Frame1Field Value
Remarks
Used for multi-frame analysis and advanced temporal processing algorithms.
Frame2
Frame 2 - the oldest frame, pushed before Frame1.
public nint Frame2Field Value
Remarks
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 - none at .NET Framework process exit, where a graph left running may still use them and the OS reclaims them.
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: a copy of currentFrame (t)
// - history.Frame1: the previous frame (t-1)
// - history.Frame2: the frame before that (t-2)
}
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 frame pushed last, and Frame2 the oldest. CurrentFrameCopy is not touched.
~HistoryFrame()
Finalizes an instance of the VisioForge.Core.Types.FastImageProcessing.HistoryFrame class. Releases unmanaged resources.
protected ~HistoryFrame()