Table of Contents

Class CarCounter

Namespace
VisioForge.Core.CV
Assembly
VisioForge.Core.CV.dll

Detects and counts vehicles crossing a defined tracking line in video streams.

public class CarCounter : IDisposable, IVideoProcessor

Inheritance

Implements

IVideoProcessor

Inherited Members

Remarks

The VisioForge.Core.CV.CarCounter class uses computer vision algorithms to detect moving vehicles in video frames and count how many cross a horizontal tracking line. It's designed for traffic monitoring, parking lot management, and vehicle flow analysis. The detector tracks vehicle movement across frames and triggers an event each time a vehicle crosses the line. Visual overlays (counter, tracking line, contours) can be drawn on frames for debugging and visualization purposes.

Constructors

CarCounter()

Initializes a new instance of the VisioForge.Core.CV.CarCounter class.

public CarCounter()

Properties

ContoursColor

Gets or sets the color used for drawing detected vehicle contours.

public Color ContoursColor { get; set; }

Property Value

Color

ContoursDraw

Gets or sets whether detected vehicle contours are drawn on the video frame.

public bool ContoursDraw { get; set; }

Property Value

bool

Remarks

Contours show the detected vehicle boundaries, useful for debugging and verifying that the detector is correctly identifying vehicles.

CounterColor

Gets or sets the color used for drawing the vehicle count overlay.

public Color CounterColor { get; set; }

Property Value

Color

CounterDraw

Gets or sets whether the vehicle count overlay is drawn on the video frame.

public bool CounterDraw { get; set; }

Property Value

bool

Initialized

Gets a value indicating whether the car counter has been initialized.

public bool Initialized { get; }

Property Value

bool

TrackingLineActiveColor

Gets or sets the active color for the tracking line when a vehicle is crossing.

public Color TrackingLineActiveColor { get; set; }

Property Value

Color

TrackingLineDefaultColor

Gets or sets the default color for the tracking line when no vehicle is crossing.

public Color TrackingLineDefaultColor { get; set; }

Property Value

Color

TrackingLineDraw

Gets or sets whether the tracking line is drawn on the video frame.

public bool TrackingLineDraw { get; set; }

Property Value

bool

Remarks

The tracking line is the horizontal line that vehicles must cross to be counted. Drawing it helps with visual verification and debugging of the detection zone.

TrackingLinePosition

Gets or sets the vertical position of the tracking line within the frame.

public double TrackingLinePosition { get; set; }

Property Value

double

Remarks

Position the line where vehicles clearly cross it in your camera view. For overhead cameras monitoring a road, 0.5 (middle) often works well. For angled views, adjust based on the road's position in the frame.

Methods

Clear()

Clears.

public void Clear()

Dispose()

Dispose.

public void Dispose()

Dispose(bool)

Dispose.

protected virtual void Dispose(bool disposing)

Parameters

disposing bool

Disposing parameter.

~CarCounter()

Finalizes an instance of the VisioForge.Core.CV.CarCounter class.

protected ~CarCounter()

GetSupportedFrameFormats()

Gets the video frame formats supported by this processor.

public VideoFormatX[] GetSupportedFrameFormats()

Returns

VideoFormatX[]

An array containing VisioForge.Core.Types.X.VideoFormatX.RGB, which is the required format for vehicle detection.

Init()

Initializes the car counter and prepares it for frame processing.

public void Init()

Remarks

This method must be called before processing any frames. It creates the internal detection engine and applies the current visual and detection settings. If already initialized, calling this method will clear and reinitialize the detector.

ProcessFrame(VideoFrame)

Processes the frame. Frame may be skipped according to the settings.

public void ProcessFrame(VideoFrame frame)

Parameters

frame VideoFrame

The frame.

ProcessFrame(VideoFrameX)

Processes a video frame to detect and count vehicles.

public void ProcessFrame(VideoFrameX frame)

Parameters

frame VideoFrameX

The video frame to analyze. Must be in RGB format.

Remarks

This method analyzes the frame for vehicle movement, detects vehicles crossing the tracking line, and raises the VisioForge.Core.CV.CarCounter.OnCarsDetected event with the updated count. The detector must be initialized with VisioForge.Core.CV.CarCounter.Init before calling this method, otherwise the frame will be ignored.

SetContext(BaseContext)

Sets the context.

public void SetContext(BaseContext context)

Parameters

context BaseContext

The context.

UpdateSettings()

Applies the current property values to the internal detection engine.

public void UpdateSettings()

Remarks

Call this method after modifying properties like VisioForge.Core.CV.CarCounter.TrackingLinePosition, VisioForge.Core.CV.CarCounter.CounterColor, or other visual settings to apply the changes to the active detector. This is automatically called by VisioForge.Core.CV.CarCounter.Init.

OnCarsDetected

Occurs when vehicles are detected crossing the tracking line.

public event EventHandler<CVCarDetectedEventArgs> OnCarsDetected

Event Type

EventHandler<CVCarDetectedEventArgs>

Remarks

This event is raised each time the detector processes a frame where vehicles have been found. The event args contain the cumulative count of vehicles that have crossed the tracking line.