Perimeter Security & Line Crossing Detection API
Viewtron AI security cameras support tripwire line crossing detection and region entry/exit detection that runs entirely on the camera hardware — no cloud service or external AI software required. When a person, vehicle, or motorcycle crosses a defined line or enters/exits a defined region, the camera sends an HTTP POST webhook to your server with the detection event data, including a full-frame overview image, a cropped image of the detected target, bounding box coordinates, and the line or region boundary.
Line crossing detection uses a start point and end point to define a tripwire. You can configure direction filtering to detect only objects crossing in a specific direction (left-to-right, right-to-left, or both). Region entry and exit detection uses a polygon zone and triggers when an object enters or leaves that area. All Viewtron IP cameras and NVRs are NDAA compliant.
The key difference from intrusion detection is that line crossing detects movement across a boundary line rather than presence within a polygon zone. Region entry/exit detects the transition into or out of a zone, rather than continuous presence.
What You Can Build
- Boundary crossing alerts — detect when people or vehicles cross a property line, fence line, or restricted area boundary
- Directional traffic monitoring — filter by crossing direction to track one-way traffic flow at gates, driveways, or corridors
- Doorway and entry counting — combine with people counting for occupancy tracking
- Loading dock monitoring — alert when vehicles enter or exit loading zones
- Parking lot entry/exit — detect vehicles crossing gate lines for access logging
- Zone transition tracking — trigger different actions when objects enter vs leave a defined region
How It Works
- Configure a tripwire line on the camera — define a start point and end point, set the crossing direction filter (both, left/right, or top/bottom)
- Or configure a region entry/exit zone — define a polygon region for AOI (Area of Interest) entry or exit detection
- Enable HTTP POST webhooks — point the camera or NVR at your server's IP and port
- Your server receives XML when a detection occurs — the POST includes alarm type, line coordinates, target bounding box, and base64 images
- Parse the event using the Viewtron Python SDK (
pip install viewtron) or Node.js SDK - Take action — save images, log to CSV, send alerts, trigger relays
Event Data Included
Each line crossing or region entry/exit webhook POST contains:
| Field | Description |
|---|---|
smartType | PEA (IPC line cross), lineCrossing (NVR), AOIENTRY (IPC entry), AOILEAVE (IPC exit) |
boundary | tripwire (line crossing) or zone polygon (region entry/exit) |
directionLine | Start and end point of the tripwire line (NVR format) |
startPoint / endPoint | Line coordinates defining the tripwire (IPC format uses lineInfo) |
rect | Bounding box of the detected target (x1, y1, x2, y2) |
eventId / targetId | Unique IDs for the event and tracked target |
status | SMART_START, SMART_PROCEDURE, or SMART_STOP |
sourceBase64Data | Full-frame JPEG image (base64 encoded) |
targetBase64Data | Cropped target JPEG image (base64 encoded) |
currentTime | Detection timestamp |
Tripwire Direction Options
The IPC tripwire configuration supports directional filtering:
| Direction | Description |
|---|---|
none | Detect crossing in both directions |
rightortop | Detect crossing from left-to-right or bottom-to-top only |
leftorbotton | Detect crossing from right-to-left or top-to-bottom only |
The NVR v2.0 lineCrossing event does not include crossing direction in the webhook POST data. The direction line coordinates are included, but not which direction the object crossed.
Parsing Line Crossing Events
- Python SDK
- Node.js SDK
- NVR XML (v2.0)
- IPC XML (v1.x)
The simplest way to receive line crossing events. The SDK's ViewtronServer handles HTTP connections, keepalives, XML parsing, and version detection — you just write the callback:
pip install viewtron
from viewtron import ViewtronServer
import os
IMG_DIR = "images"
os.makedirs(IMG_DIR, exist_ok=True)
def on_event(event, client_ip):
if event.category != "intrusion":
return
print(f"Line crossing detected from {client_ip}")
print(f" Type: {event.get_alarm_type()} ({event.get_alarm_description()})")
overview = event.get_source_image_bytes()
if overview:
with open(f"{IMG_DIR}/{event.get_time_stamp()}-line-crossing-overview.jpg", "wb") as f:
f.write(overview)
target = event.get_target_image_bytes()
if target:
with open(f"{IMG_DIR}/{event.get_time_stamp()}-line-crossing-target.jpg", "wb") as f:
f.write(target)
server = ViewtronServer(port=5002, on_event=on_event)
server.serve_forever()
See the Python SDK reference for the full list of methods and event classes.
npm install viewtron-sdk
const { ViewtronServer } = require('viewtron-sdk');
const fs = require('fs');
fs.mkdirSync('images', { recursive: true });
const server = new ViewtronServer({ port: 5002 });
server.on('event', (event, clientIP) => {
if (event.category !== 'intrusion') return;
console.log(`Line crossing detected from ${clientIP}`);
console.log(` Type: ${event.eventType} (${event.targetType})`);
if (event.sourceImageBytes) {
fs.writeFileSync(
`images/${Date.now()}-line-crossing-overview.jpg`,
event.sourceImageBytes
);
}
if (event.targetImageBytes) {
fs.writeFileSync(
`images/${Date.now()}-line-crossing-target.jpg`,
event.targetImageBytes
);
}
});
server.start();
The NVR v2.0 format uses lineCrossing with a directionLine defining the tripwire start and end points:
<?xml version="1.0" encoding="UTF-8"?>
<config version="2.0.0" xmlns="http://www.ipc.com/ver10">
<messageType>alarmData</messageType>
<deviceInfo>
<deviceName><![CDATA[Driveway]]></deviceName>
<ip><![CDATA[192.168.0.55]]></ip>
<mac><![CDATA[58:5B:69:40:F4:0D]]></mac>
<channelId>2</channelId>
</deviceInfo>
<smartType>lineCrossing</smartType>
<currentTime>1772056914604000</currentTime>
<eventInfo>
<item>
<eventId>1409</eventId>
<targetId>1309</targetId>
<boundary>tripwire</boundary>
<directionLine>
<startPoint><x>3579</x><y>2550</y></startPoint>
<endPoint><x>3655</x><y>9797</y></endPoint>
</directionLine>
<rect><x1>3494</x1><y1>4409</y1><x2>4261</x2><y2>9791</y2></rect>
</item>
</eventInfo>
<sourceDataInfo>
<sourceBase64Length>400924</sourceBase64Length>
<sourceBase64Data>... (base64 JPEG) ...</sourceBase64Data>
</sourceDataInfo>
<targetListInfo>
<item>
<targetId>1309</targetId>
<targetType>person</targetType>
<targetImageData>
<targetBase64Length>78796</targetBase64Length>
<targetBase64Data>... (base64 JPEG) ...</targetBase64Data>
</targetImageData>
</item>
</targetListInfo>
</config>
See the NVR Event Format reference for the complete v2.0 XML structure.
IPC uses the same PEA smartType for both intrusion and line crossing. Line crossing events contain a <tripwire> block instead of <perimeter>:
<?xml version="1.0" encoding="UTF-8" ?>
<config version="1.7" xmlns="http://www.ipc.com/ver10">
<smartType type="openAlramObj">PEA</smartType>
<deviceName type="string"><![CDATA[FrontGate]]></deviceName>
<currentTime type="tint64">1774792701902505</currentTime>
<tripwire>
<tripInfo type="list" count="1">
<item>
<eventId type="uint32">3410</eventId>
<targetId type="uint32">3210</targetId>
<status type="perStatus">SMART_START</status>
<startPoint>
<x type="uint32">3579</x>
<y type="uint32">2550</y>
</startPoint>
<endPoint>
<x type="uint32">3655</x>
<y type="uint32">9797</y>
</endPoint>
<rect>
<x1 type="uint32">3494</x1><y1 type="uint32">4409</y1>
<x2 type="uint32">4261</x2><y2 type="uint32">9791</y2>
</rect>
</item>
</tripInfo>
</tripwire>
<!-- sourceDataInfo and listInfo with base64 images -->
</config>
See the IPC Event Format reference for the complete v1.x XML structure.
Relevant API Endpoints
| Endpoint | Purpose | Reference |
|---|---|---|
| GetSmartTripwireConfig | Read tripwire line crossing configuration | Line Crossing Config |
| GetSmartAoiEntryConfig | Read region entry detection configuration | Region Entry/Exit Config |
| GetSmartAoiLeaveConfig | Read region exit detection configuration | Region Entry/Exit Config |
| SetHttpPostConfig | Configure webhook destination | Webhook Config |
| GetAlarmStatus | Poll current alarm state (tripwireAlarm, aoiEntryAlarm, aoiLeaveAlarm) | Alarm Status |
Integrations
Viewtron line crossing detection also integrates with automation platforms via published packages:
| Platform | Package | What It Does |
|---|---|---|
| Home Assistant | viewtron-home-assistant | Line crossing events as native HA sensors — automate gates, lights, notifications |
| Node-RED | node-red-contrib-viewtron | Line crossing events direct to Node-RED flows — no middleware needed |
Related Applications
- Human Detection & Intrusion — polygon zone intrusion detection (vs line crossing)
- People Counting & Traffic Analytics — count objects crossing a line with running totals
- Relay Control & IoT Automation — trigger relays based on line crossing events
- Webhook Event Notification — complete webhook setup and format reference
Related Products
- Viewtron AI Security Cameras — IP cameras with built-in line crossing and region entry/exit detection
- Viewtron IP Camera NVRs — NVRs with HTTP POST event forwarding
Questions & Development Inquiries
- Email: mike@viewtron.com
- Phone: 561-433-8488
- Forum: NVR Webhook Setup Guide
Mike Haldas is available for questions, consultation, and custom software development for Viewtron API related projects. Email details about your project to mike@viewtron.com.