Skip to main content

Counting Events

Overview​

Counting events are generated when cameras count people or vehicles crossing a line or entering an area. All counting events have category == "counting".

Two API versions produce counting events:

  • IPC v1.x -- uses the IntrusionDetection class for PASSLINECOUNT and TRAFFIC alarm types
  • NVR v2.0 -- dedicated TargetCountingByLine and TargetCountingByArea classes

Event Types​

IPC v1.x​

ClasssmartTypeAlarm Description
IntrusionDetectionPASSLINECOUNTLine Crossing Target Count
IntrusionDetectionTRAFFICIntrusion Target Count

IPC counting events reuse the IntrusionDetection class. They share the same base methods as other IPC events -- timestamps, camera name, images, and get_target_types() for the target filter (person, car, motor).

NVR v2.0​

ClasssmartTypeAlarm Description
TargetCountingByLinetargetCountingByLineTarget Counting by Line
TargetCountingByAreatargetCountingByAreaTarget Counting by Area

NVR counting events use the standard v2.0 base class (APIpostV2). They include channel ID, microsecond timestamps, and overview/target images when available.

IPC vs NVR Comparison​

FeatureIPC v1.xNVR v2.0
Line countingYes (PASSLINECOUNT)Yes (targetCountingByLine)
Area countingNoYes (targetCountingByArea)
Target type filterVia get_target_types()Parsed from targetListInfo
Channel IDNoYes (get_channel_id())
ImagesYesYes

Common Properties​

Available on all counting events (inherited from the base event classes):

MethodReturnsDescription
get_ip_cam()strCamera device name
get_alarm_type()strRaw alarm type code (e.g., "PASSLINECOUNT", "targetCountingByLine")
get_alarm_description()strHuman-readable description
get_time_stamp_formatted()strTimestamp like "2026-04-09 15:30:45"
get_time_stamp()strUnix timestamp string (for filenames)
source_image_exists()boolTrue if an overview/scene image is available
target_image_exists()boolTrue if a target crop image is available
get_source_image_bytes()bytes or NoneOverview image as JPEG bytes
get_target_image_bytes()bytes or NoneTarget crop image as JPEG bytes

IPC-only:

MethodReturnsDescription
get_target_types()strSupported target types from the camera (person, car, motor)

NVR-only:

MethodReturnsDescription
get_channel_id()strNVR channel number

Code Examples​

Basic Count Handling​

def handle_event(event, client_ip):
if event.category == "counting":
alarm = event.get_alarm_description()
camera = event.get_ip_cam()
print(f"Count event: {alarm} on {camera}")

Filtering Line vs Area​

def handle_event(event, client_ip):
if event.category == "counting":
alarm_type = event.get_alarm_type()

if alarm_type in ("PASSLINECOUNT", "targetCountingByLine"):
print("Line crossing count")
elif alarm_type == "targetCountingByArea":
print("Area count")

Distinguishing IPC vs NVR​

from viewtron.events import TargetCountingByLine, TargetCountingByArea

def handle_event(event, client_ip):
if event.category == "counting":
if isinstance(event, (TargetCountingByLine, TargetCountingByArea)):
# NVR v2.0 — has channel ID
print(f"NVR channel {event.get_channel_id()}: {event.get_alarm_description()}")
else:
# IPC v1.x — has target type filter
print(f"IPC count: {event.get_alarm_description()}")
print(f"Target types: {event.get_target_types()}")