TcvPipeline

June 12, 2026 · View on GitHub

← Documentation · Components · Cookbook → pipeline

TcvPipeline is a chain of Mat → Mat stages. Each stage is a Stages item with StageType and parameters in Operation. Errors are handled by ErrorPolicy (default: passthrough of the original frame).

Infrastructure

Property / APIDescription
ProcessEveryNprocess every N-th frame
ErrorPolicyepPassthrough, epSkipStage, epStop
Presetquick chain load (table below)
SaveToIni / LoadFromInistage type + Enabled (operation params — OI/code)
OnBeforeStage / OnAfterStageCancel in OnBeforeStage skips the stage
OnStageTimingstage time in ms

Presets

PresetStages
ppEdgesColor → Blur(5) → Canny(80/160)
ppNightVisionCLAHE → BrightnessContrast(1.2, +10)
ppDenoiseSharpDenoise → Sharpen
ppContoursColor → Contours
ppMotionDetectBackgroundSubtract
ppLinesHoughLinesP
ppOpticalFlowOpticalFlow
ppGrabCutGrabCut

Stages (63 types)

Color, Blur, Threshold, Canny, Morphology, Resize, Custom, AdaptiveThreshold, BilateralFilter, EqualizeHist, Sobel, Invert, Clahe, InRange, MorphologyEx, ColorMap, BrightnessContrast, PyrDown, PyrUp, Laplacian, Scharr, Denoise, DistanceTransform, Crop, Normalize, Sharpen, Bitwise, Rotate, WarpPolar, Filter2D, CornerHarris, TemporalBlend, MatchTemplate, Contours, ChannelExtract, Flip, OrthoRotate, Gamma, AddWeighted, PyrMeanShift, SepFilter2D, SqrBoxFilter, SpatialGradient, CornerMinEigenVal, Integral, AbsDiff, AutoContrast, MergeChannels, Inpaint, Undistort, Remap, CustomLUT, HoughLinesP, HoughCircles, ConnectedComponents, BackgroundSubtract, DebugText, PhaseCorrelate, BlendLinear, ReferenceDiff, OpticalFlow, RunningAvg, GrabCut, Watershed.

Stage enhancements

Color (ColorPreset: Gray/HSV/Lab/RGB) · Canny (L2gradient) · Morphology/MorphologyEx (BorderMode, BorderValue) · InRange (Red/Green/Blue HSV presets) · Resize (ResizeMode=Scale, ScaleX/ScaleY, KeepAspect).

Overlay and analysis events

StageEventData
MatchTemplateOnMatchResultmax val, point
ContoursOnContoursResultcontour count
HoughLinesPOnHoughLinesResultline segments
HoughCirclesOnHoughCirclesResultx, y, r
ConnectedComponentsOnConnectedComponentsResultLabelId, area, rect
BackgroundSubtractOnForegroundMaskResultforeground fraction
PhaseCorrelateOnPhaseCorrelateResultshift, response
OpticalFlowOnOpticalFlowResultmean magnitude

DrawOverlay (default True) draws markup on the frame; events provide metrics without drawing.

ConnectedComponents — ColormapSeed

When DrawOverlay=False, output is a JET colormap of labels.

ColormapSeedBehavior
0 (default)normalize by MaxVal; colors may shift when blob count changes
≠ 0stable index (LabelId * Seed) mod 254 + 1

BackgroundSubtract (MOG2 / KNN)

APIDescription
Resetexplicit background model reset
ResetOnAssigndefault True: Assign resets the model; False — parameters only
setters Algorithm, History, …recreate the subtractor

Tier 3 — stateful / second input

StageNotes
TemporalBlendEMA (accumulateWeighted)
AbsDiffdiff with previous frame
AddWeighted, Bitwise, Inpaint, MergeChannelsOperandPath / MaskPath / channel files
BlendLinearOperandPath + Weight1/Weight2
ReferenceDiffReferencePath + absdiff
OpticalFlowFarneback; Output: HSV / magnitude / overlay
RunningAvgaccumulate, average since session start
GrabCutROI rect; mask / foreground / overlay
Watershedmarkers: border=BG, rect=FG
DebugTextputText + optional rectangle

Example

Pipeline1.Stages.Add.StageType := stClahe;
Pipeline1.Stages.Add.StageType := stCanny;
Pipeline1.Preset := ppMotionDetect;

with TcvBackgroundSubtractOperation(Pipeline1.Stages[0].Operation) do
begin
  Algorithm := bsMOG2;
  OnForegroundMaskResult := OnFg;
end;

Demo: Test/Utit2. Code examples: Cookbook