Class VideoStabilizationBlock
- Namespace
- VisioForge.Core.MediaBlocks.OpenCV
- Assembly
- VisioForge.Core.dll
Real-time video stabilization (deshake) block.
Removes camera shake from a live or file video stream by estimating global inter-frame
motion (translation and rotation) with sparse optical flow, smoothing the resulting camera
trajectory with a causal moving-average window, and warping each frame back onto the smoothed
path. A small centre zoom (crop ratio) hides the borders exposed by compensation. Latency is
zero - only past frames are used for smoothing. Backed by the OpenCV vfdeshake GStreamer
element, so it requires the OpenCV SDK redistributable (currently Windows only).
Implements the VisioForge.Core.MediaBlocks.MediaBlock.
Implements the VisioForge.Core.MediaBlocks.IMediaBlockInternals.
Implements the VisioForge.Core.MediaBlocks.IVideoProcessingBlock, so the block can
also be inserted into a VideoCaptureCoreX / MediaPlayerCoreX video chain with
Video_Processing_AddBlock.
Implements the IDisposable.
public class VideoStabilizationBlock : MediaBlock, IMediaBlockInternals, IVideoProcessingBlock, IMediaBlock, IDisposableInheritance
Implements
Inherited Members
Extension Methods
Constructors
VideoStabilizationBlock(VideoStabilizationSettings)
Initializes a new instance of the VisioForge.Core.MediaBlocks.OpenCV.VideoStabilizationBlock class with the specified stabilization settings.
public VideoStabilizationBlock(VideoStabilizationSettings settings)Parameters
settingsVideoStabilizationSettings-
The stabilization configuration settings.
VideoStabilizationBlock()
Initializes a new instance of the VisioForge.Core.MediaBlocks.OpenCV.VideoStabilizationBlock class with default stabilization settings.
public VideoStabilizationBlock()Properties
Input
Gets the input pad for connecting video sources to be stabilized.
public override MediaBlockPad Input { get; }Property Value
Inputs
Gets all input pads for this stabilization block.
public override MediaBlockPad[] Inputs { get; }Property Value
Output
Gets the output pad for connecting to downstream processing blocks.
public override MediaBlockPad Output { get; }Property Value
Outputs
Gets all output pads for this stabilization block.
public override MediaBlockPad[] Outputs { get; }Property Value
Settings
Gets or sets the stabilization configuration settings.
public VideoStabilizationSettings Settings { get; set; }Property Value
Type
Gets the media block type identifier.
public override MediaBlockType Type { get; }Property Value
Methods
ApplySettings()
Applies the current VisioForge.Core.MediaBlocks.OpenCV.VideoStabilizationBlock.Settings to the running element. The vfdeshake
element re-reads its properties every frame, so this retunes the stabilization live
(enable/disable, smoothing radius, crop ratio, limits) without rebuilding the pipeline.
No-op until the block has been built, and after it has been disposed.
public void ApplySettings()Remarks
Safe to call from any thread. When the block runs inside an X engine the engine disposes it from a pipeline thread, so the retune is serialized against that disposal.
Build()
Constructs and initializes the OpenCV stabilization element within the pipeline.
public override bool Build()Returns
- bool
-
trueif the stabilization element was successfully built;falseotherwise.
CleanUp()
Releases all resources and performs cleanup operations for this stabilization block.
public void CleanUp()Dispose(bool)
Releases unmanaged and - optionally - managed resources.
protected override void Dispose(bool disposing)Parameters
disposingbool-
trueto release both managed and unmanaged resources;falseto release only unmanaged resources.
GetCore()
Gets the core BaseElement wrapper that provides additional functionality around the OpenCV stabilization element.
public BaseElement GetCore()Returns
- BaseElement
-
The BaseElement wrapper instance.
GetElement()
Gets the underlying GStreamer element that performs the stabilization operation.
public Element GetElement()Returns
- Element
-
The GStreamer Element instance representing the OpenCV deshake filter.
Remarks
The returned element belongs to the block and is torn down when the block is disposed - do not cache it across a stop.
IsAvailable()
Determines whether this media block is available. Correct NuGet SDK redist should be included into your project.
Checks for OpenCV library availability and the vfdeshake element.
public static bool IsAvailable()Returns
- bool
-
trueif OpenCV stabilization functionality is available; otherwise,false.
RemoveElementsFromPipeline()
Removes the videoconvert and vfdeshake elements from the pipeline. Called by the pipeline during teardown, and by VisioForge.Core.MediaBlocks.OpenCV.VideoStabilizationBlock.Build on a failed build so the elements are not left orphaned (added and linked but unreachable) after Build returns false. Idempotent.
public override void RemoveElementsFromPipeline()IMediaBlockInternals.SetContext(MediaBlocksPipeline)
Associates this stabilization block with a pipeline and initializes its internal context.
void IMediaBlockInternals.SetContext(MediaBlocksPipeline pipeline)Parameters
pipelineMediaBlocksPipeline-
The MediaBlocksPipeline instance that will manage this block.