Line Crossing Counter

Counts how many particular tracked objects crossed each line

Overview

The Line Counter node keeps track of the number of objects that cross a virtual line in the video, the direction they cross it in, and adds the line counting metadata to the frame metadata. This node makes it easy to build common use cases such as People counting, Parking lot occupancy counting, etc.

This node supports Lines with one or more segments, allowing you to be as granular as you need for your counting needs.

This node requires a AI Model Node and a Track Objects Node before it in order to function properly.

Inputs & Outputs

  • Inputs : 1, Media Format : Raw Video
  • Outputs : 1, Media Format: Raw Video
  • Output Metadata : Line Counter Information

Properties

PropertyDescriptionTypeDefaultRequired
line_labelsLine LabelsstringNo
linesLines. Conditional on line_labels. Format: comma-separated normalized x0,y0,x1,y1 coordinates; separate multiple lines with semicolons.stringnullNo
objects_to_trackex. car, person, car.red. Object types and classes to be counted. Leave blank to count all.model-labelsnullNo
crossing_bufferInterval during which subsequent line crossings by the same object will be ignored. Unit: seconds.float0.5Yes
flow_rate_intervalTime interval for calculating flow rate (objects per interval). Set to 0 to disable flow rate calculation. Unit: seconds.float0No
trigger_eventsTrigger these Events when an object crosses the line. Options: Disabled (null); Object crossed line (crossed); Object crossed line Dir 1 (crossed_dir1); Object crossed line Dir 2 (crossed_dir2).enumnullNo
event_templateTemplate for the event name. Leave blank to use defaults. Available variables: {object_type}, {object_attributes}, {line}, {direction}.stringnullNo
add_object_attributesAdd specified labels as attributes to objects that cross the line. Options: None (none); Direction (direction); Line (line); Line_Direction (line_direction).enumnoneNo
display_lineDisplay line on video?booltrueNo
display_objectsDisplay objects on video?booltrueNo
tracking_modeTracking mode. Options: Centroid (centroid); Top center (top-center); Bottom center (bottom-center); Left center (left-center); Right center (right-center).enumcentroidNo
dir1_labelLabel for Direction 1 (blue color in the lines widget).stringnullNo
dir2_labelLabel for Direction 2 (red color in the lines widget).stringnullNo
persistent_storagePersist analytics across restarts?boolfalseNo

Events

Triggering specific events using trigger_events and event_template fields allows you to add Events to metadata. These Events can then be processed by downstream nodes to publish metrics to a Dashboard, or send notifications or trigger alarms / bookmarks.

Output Metadata

The fields below are declared by this node's metadata schema; the JSON values are representative examples.

PathTypeDescription
nodes.<node_id>.lines.<line_label>.dir1_labelstringConfigured label for line-crossing direction 1.
nodes.<node_id>.lines.<line_label>.dir2_labelstringConfigured label for line-crossing direction 2.
nodes.<node_id>.lines.<line_label>.total_objects_crossedintegerCumulative number of objects that crossed the line in either direction.
nodes.<node_id>.lines.<line_label>.total_objects_crossed_deltaintegerWhen one or more objects cross the line in either direction
nodes.<node_id>.lines.<line_label>.dir1_objects_crossedintegerCumulative number of objects that crossed in direction 1.
nodes.<node_id>.lines.<line_label>.dir1_objects_crossed_deltaintegerWhen one or more objects cross the line in direction 1 (blue arrow)
nodes.<node_id>.lines.<line_label>.dir2_objects_crossedintegerCumulative number of objects that crossed in direction 2.
nodes.<node_id>.lines.<line_label>.dir2_objects_crossed_deltaintegerWhen one or more objects cross the line in direction 2 (red arrow)
nodes.<node_id>.lines.<line_label>.coordsarrayArray of pixel coordinates defining the configured ROI or line.
nodes.<node_id>.lines.<line_label>.cur_dir1_objectsarrayArray of tracking IDs of objects currently crossing in direction 1.
nodes.<node_id>.lines.<line_label>.cur_dir2_objectsarrayArray of tracking IDs of objects currently crossing in direction 2.
nodes.<node_id>.lines.<line_label>.flow_rate_intervalintegerTime window in seconds used to calculate flow rates.
nodes.<node_id>.lines.<line_label>.total_flow_rateintegerNumber of crossings in either direction during the flow-rate window.
nodes.<node_id>.lines.<line_label>.dir1_flow_rateintegerNumber of direction 1 crossings during the flow-rate window.
nodes.<node_id>.lines.<line_label>.dir2_flow_rateintegerNumber of direction 2 crossings during the flow-rate window.
nodes.<node_id>.events_deltaintegerWhen one or more Line Crossing events are triggered
nodes.<node_id>.eventsarrayArray of event names generated by this node for the current frame.
nodes.<node_id>.typestringIdentifies the node type that produced this metadata.

JSON example

{
  "nodes": {
    "annotate_line_counter1": {
      "events": [],
      "events_delta": 0,
      "lines": {
        "line1": {
          "coords": [[<point1_x>, <point1_y>],[<point2_x>, <point2_y> ]],
          "cur_dir1_objects": [ <object_tracking_id>,<object_tracking_id> ],
          "cur_dir2_objects": [ <object_tracking_id>,<object_tracking_id> ],
          "dir1_flow_rate": 0,
          "dir1_label": "example",
          "dir1_objects_crossed": 0,
          "dir1_objects_crossed_delta": 0,
          "dir2_flow_rate": 0,
          "dir2_label": "example",
          "dir2_objects_crossed": 0,
          "dir2_objects_crossed_delta": 0,
          "flow_rate_interval": 0,
          "total_flow_rate": 0,
          "total_objects_crossed": 0,
          "total_objects_crossed_delta": 0
        }
      },
      "type": "annotate_line_counter"
    }
  }
}

Object labels and attributes

  • Object labels/classes added: None.
  • Object attribute labels/classes added: Depending on add_object_attributes, the configured line label (35001), crossing direction label (35002), or <line>_<direction> label (35003).

Did this page help you?