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
IntrusionDetectionclass forPASSLINECOUNTandTRAFFICalarm types - NVR v2.0 -- dedicated
TargetCountingByLineandTargetCountingByAreaclasses
Event Types
IPC v1.x
| Class | smartType | Alarm Description |
|---|---|---|
IntrusionDetection | PASSLINECOUNT | Line Crossing Target Count |
IntrusionDetection | TRAFFIC | Intrusion 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
| Class | smartType | Alarm Description |
|---|---|---|
TargetCountingByLine | targetCountingByLine | Target Counting by Line |
TargetCountingByArea | targetCountingByArea | Target 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
| Feature | IPC v1.x | NVR v2.0 |
|---|---|---|
| Line counting | Yes (PASSLINECOUNT) | Yes (targetCountingByLine) |
| Area counting | No | Yes (targetCountingByArea) |
| Target type filter | Via get_target_types() | Parsed from targetListInfo |
| Channel ID | No | Yes (get_channel_id()) |
| Images | Yes | Yes |
Common Properties
Available on all counting events (inherited from the base event classes):
| Method | Returns | Description |
|---|---|---|
get_ip_cam() | str | Camera device name |
get_alarm_type() | str | Raw alarm type code (e.g., "PASSLINECOUNT", "targetCountingByLine") |
get_alarm_description() | str | Human-readable description |
get_time_stamp_formatted() | str | Timestamp like "2026-04-09 15:30:45" |
get_time_stamp() | str | Unix timestamp string (for filenames) |
source_image_exists() | bool | True if an overview/scene image is available |
target_image_exists() | bool | True if a target crop image is available |
get_source_image_bytes() | bytes or None | Overview image as JPEG bytes |
get_target_image_bytes() | bytes or None | Target crop image as JPEG bytes |
IPC-only:
| Method | Returns | Description |
|---|---|---|
get_target_types() | str | Supported target types from the camera (person, car, motor) |
NVR-only:
| Method | Returns | Description |
|---|---|---|
get_channel_id() | str | NVR 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()}")
Related Pages
- ViewtronEvent -- common properties and category routing
- API Reference: Line Counting -- raw XML endpoint documentation, counting zone configuration