Table of Contents

Class FaceRecognitionBlock

Namespace
VisioForge.Core.MediaBlocks.AI
Assembly
VisioForge.Core.AI.dll

A face recognition (face identity) media block. Runs a two-stage pipeline: a YuNet detector locates faces and their five landmarks, each face is aligned and embedded (SFace / ArcFace), and the embedding is matched 1:N against an enrolled VisioForge.Core.Types.X.AI.FaceGallery. Implements the VisioForge.Core.MediaBlocks.MediaBlock. Implements the VisioForge.Core.MediaBlocks.IMediaBlockInternals.

public class FaceRecognitionBlock : MediaBlock, IMediaBlock, IDisposable, IMediaBlockInternals

Inheritance

MediaBlock

Implements

IMediaBlock
IMediaBlockInternals

Inherited Members

MediaBlock._isBuilt
MediaBlock._pipeline
MediaBlock._pipelineCtx
MediaBlock.GetPipelineContext()
MediaBlock.SetPipelineContext(BlockPipelineContext)
MediaBlock.SetPipeline(MediaBlocksPipeline)
MediaBlock.Context
MediaBlock.Name
MediaBlock.IsBuilt
MediaBlock.Owner
MediaBlock.Type
MediaBlock.ID
MediaBlock.Input
MediaBlock.Inputs
MediaBlock.Output
MediaBlock.Outputs
MediaBlock.HasInputs
MediaBlock.HasOutputs
MediaBlock.Build()
MediaBlock.CreateElements()
MediaBlock.AddElementsToPipeline()
MediaBlock.RemoveElementsFromPipeline()
MediaBlock.DeepCopy(string)
MediaBlock.Reset()
MediaBlock.ToYAMLBlock()
MediaBlock.ClearPads()
MediaBlock.Dispose(bool)
MediaBlock.Dispose()

Remarks

Recognition runs on a background worker so live video never stalls; the streaming thread only draws the most recent faces onto each frame. The default models are the OpenCV Zoo YuNet detector (MIT) and SFace recognizer (Apache-2.0).

Constructors

FaceRecognitionBlock(FaceRecognitionSettings)

Initializes a new instance of the VisioForge.Core.MediaBlocks.AI.FaceRecognitionBlock class.

public FaceRecognitionBlock(FaceRecognitionSettings settings)

Parameters

settings FaceRecognitionSettings

The recognizer settings. Must specify valid detector and embedding model paths.

Exceptions

ArgumentNullException

Thrown when settings is null.

Properties

ActiveProvider

Gets the execution provider the face sessions actually engaged. Valid after the block has been built; reports VisioForge.Core.Types.X.AI.OnnxExecutionProvider.CPU otherwise.

public OnnxExecutionProvider ActiveProvider { get; }

Property Value

OnnxExecutionProvider

DroppedFrameCount

Gets the number of frames that arrived while the background worker was still busy and were therefore skipped for recognition (the live video is unaffected).

public long DroppedFrameCount { get; }

Property Value

long

Gets the enrolled face gallery this block matches detected faces against. Add identities with VisioForge.Core.MediaBlocks.AI.FaceRecognitionBlock.Enroll(System.String,SkiaSharp.SKBitmap) or directly via the gallery API.

public FaceGallery Gallery { get; }

Property Value

FaceGallery

Input

Gets the primary input pad.

public override MediaBlockPad Input { get; }

Property Value

MediaBlockPad

Inputs

Gets the array of all input pads.

public override MediaBlockPad[] Inputs { get; }

Property Value

MediaBlockPad[]

LastInferenceTimeMs

Gets the wall-clock time, in milliseconds, the most recent recognition took (detection + embedding + matching). It runs on a background thread; use this to tune VisioForge.Core.Types.X.AI.FaceRecognitionSettings.FramesToSkip.

public float LastInferenceTimeMs { get; }

Property Value

float

Output

Gets the primary output pad.

public override MediaBlockPad Output { get; }

Property Value

MediaBlockPad

Outputs

Gets the array of all output pads.

public override MediaBlockPad[] Outputs { get; }

Property Value

MediaBlockPad[]

Type

Gets the type of the media block.

public override MediaBlockType Type { get; }

Property Value

MediaBlockType

Methods

Build()

Constructs the internal GStreamer elements and pads for this block.

public override bool Build()

Returns

bool

true if successful, false otherwise.

CleanUp()

Cleans up internal resources, specifically the GStreamer element.

public void CleanUp()

Dispose(bool)

Releases unmanaged and - optionally - managed resources.

protected override void Dispose(bool disposing)

Parameters

disposing bool

true to release both managed and unmanaged resources; false to release only unmanaged resources.

Enroll(string, SKBitmap)

Enrolls a face from a still image under the given identity. Detects the most prominent face, aligns and embeds it, and adds the embedding to the gallery. Multiple photos can be enrolled under one name.

public bool Enroll(string name, SKBitmap image)

Parameters

name string

The identity name.

image SKBitmap

The source image containing one clearly visible face.

Returns

bool

true when a face was found and enrolled; otherwise false.

Enroll(string, string)

Enrolls a face from an image file under the given identity. See VisioForge.Core.MediaBlocks.AI.FaceRecognitionBlock.Enroll(System.String,SkiaSharp.SKBitmap).

public bool Enroll(string name, string imagePath)

Parameters

name string

The identity name.

imagePath string

Path to an image file containing one clearly visible face.

Returns

bool

true when a face was found and enrolled; otherwise false.

GetCore()

Gets the core GStreamer element wrapped by this block.

public BaseElement GetCore()

Returns

BaseElement

The VisioForge.Core.GStreamer.Base.BaseElement wrapper, or null if not built yet.

GetElement()

Gets the GStreamer element instance.

public Element GetElement()

Returns

Element

The Gst.Element, or null if not built yet.

IMediaBlockInternals.SetContext(MediaBlocksPipeline)

Sets the pipeline context for this block.

void IMediaBlockInternals.SetContext(MediaBlocksPipeline pipeline)

Parameters

pipeline MediaBlocksPipeline

The pipeline.

OnFacesIdentified

Event raised when one or more faces are recognized in a video frame. Faces that did not match any gallery entry are still reported with a null identity.

public event EventHandler<FacesIdentifiedEventArgs> OnFacesIdentified

Event Type

EventHandler<FacesIdentifiedEventArgs>

See Also

MediaBlock
IMediaBlockInternals