A virtual fence rule is drawn in five minutes on installation day, then for months it either raises alarms at midnight for leaves or misses the person who actually climbs the fence. In both cases, the problem is usually not in the software but in the rule itself: the wrong rule type, a line drawn in midair, a randomly chosen duration threshold. Below we explain matching rule types to scenarios, zone geometry, direction, duration, class and schedule parameters, and how to document and test a rule before putting it into service.
Rule types and where to use them
Manufacturers use different names, but the basic rule families are the same. Choosing the right type is more decisive than all the fine tuning that follows.
| Rule type | What it detects | Typical scenario |
|---|---|---|
| Line crossing (tripwire) | An object crossing a defined line in a given direction | Perimeter fence, dock opening, prohibited passage corridor |
| Area intrusion | An object being inside a zone for a given time | Inside the facility after hours, transformer area, roof |
| Area entry / exit | Crossing the zone boundary from outside in or inside out | Machine safety area, controlled warehouse section |
| Loitering | An object staying in a zone longer than a threshold time | In front of an ATM, loading door, car park entrance |
| Multi-line (double line) | Two lines being crossed in sequence | Filtering out a person walking along the fence |
Line crossing is focused on the “moment”: it produces an event in the frame where the object crosses the line. Area intrusion is focused on “state”: it waits for the object to stay in the zone for a set time. This difference determines false alarm behavior. A branch swaying in the wind can touch the line once and trigger a tripwire; for the same branch to trigger an area intrusion rule, it must both be classified as an object and exceed the duration threshold.
The selection rule is simple: if the crossing itself matters (climbing the fence), line crossing; if being in the zone matters (a person in an after-hours area), area intrusion; if the time spent matters, a loitering rule.
Zone and line geometry
Analytics models track an object with a bounding box and often evaluate the rule against a single reference point of this box. That point is usually the bottom center of the box, that is, the person’s foot level. That’s why zones and lines are drawn on the ground plane. A line drawn at head height doesn’t match the real boundary on the ground in the camera’s perspective. This is a common geometry mistake.
Geometry rules for line crossing
- Draw the line a few meters inside on the protected side, not exactly on top of the physical boundary. A line on the fence can be triggered by the foot point of a person walking outside the fence.
- Don’t leave the line close to the edge of the image. The model must be able to track the object for a few frames before and after the line; an object appearing at the edge crosses the line before it’s classified.
- On long perimeter lines, use segmented lines that follow the perspective instead of a single long line.
Geometry rules for area intrusion
- Limit the zone to the area where the object is visible at full size. Don’t include distant areas where the target shrinks to a few pixels; classification there is unreliable.
- Leave trees, flags, water surfaces, roads and reflective surfaces outside the zone, or mask them with an exclusion zone.
- Check patches of ground reflecting headlights or the sun separately by night and by day. A scene that looks clean by day is a different scene at night.
How many pixels the target must occupy in the frame and the effect of the tilt angle directly limit rule geometry; details are in the effect of camera angle and resolution on analytics accuracy guide.
Direction, duration and object class parameters
Direction filter: For line crossing, A→B, B→A or both directions are selected. In perimeter security, only crossing from outside in should raise an alarm; a security guard leaving from inside shouldn’t produce an event. For area entry/exit rules too, only the relevant direction is selected. A perimeter rule left on both directions means an alarm every time the patrol passes.
Minimum duration: In area intrusion, the time the object must stay in the zone filters out short-lived false detections. If it’s too short, shadows, birds and momentary classification errors turn into alarms; if it’s too long, a person running through is missed. Calculate the value from the relationship between zone depth and crossing time. Worked example: if the zone depth is 6 meters and normal walking speed is about 1.2–1.5 m/s, a person crosses the zone in 4–5 seconds. A running person (about 3–5 m/s) crosses the same depth in 1.2–2 seconds. In this case, raising the minimum duration above 1 second creates a risk of missing a running person; if a longer threshold is needed, increase the zone depth. The few frames the system spends classifying the object also come out of this budget. The duration threshold is chosen by calculation, not by guessing.
Loitering threshold: In a loitering rule, the threshold should be well above normal usage time. If handing over paperwork at a loading door takes a few minutes, setting the threshold below that triggers the rule at every delivery.
Object class: Selecting person or vehicle (sub-classes such as bicycle and motorcycle on some systems) markedly reduces false alarms compared with motion detection without classification. However, classification reliability depends on the target’s pixel size and on light; in distant and dark areas, the confidence score for the person class drops. We covered the reliability limits of detection in the person detection with AI cameras article.
Size filter: Some systems let you define minimum and maximum object size. Because of perspective, a distant person can look smaller than a nearby cat. Use the size filter only on systems with perspective calibration; otherwise rely on the class filter.
Scheduling and commissioning
A rule doesn’t mean the same thing at every hour. A corridor staff routinely pass through during working hours is a prohibited zone at night. Define the schedule together with the facility’s shift and security plan:
- Keep after-hours and weekend schedules separate, and define an exception calendar for public holidays.
- During busy passage periods such as shift changes, turn the rule off or put it in recording-only mode (marking events without raising alarms).
- Rules fail not at installation but at commissioning. Run a new rule in “recording only” mode for at least a week first, review the events, then put it into alarm mode.
- Verify that the camera clock and the VMS clock are equal via NTP. If the clock has drifted, the schedule kicks in at the wrong time, and the first to notice is usually the night shift.
Rule design table
The table below is a starting point, not a recipe. Verify the values on site during the pilot.
| Scenario | Rule type | Direction / duration | Class and time |
|---|---|---|---|
| Perimeter fence | Double line or single line | Outside to inside; instant | Person; 24/7 |
| Inside the site after hours | Area intrusion | Short duration threshold | Person, vehicle; after hours |
| Machine safety area | Area entry | Inbound | Person; while the machine is running |
| Loading door | Dwell | Above normal delivery time | Person, vehicle; 24/7 |
| Roof / transformer area | Area intrusion | Short duration threshold | Person; 24/7, maintenance exception |
Rule documentation and testing
In enterprise camera systems, if rules aren’t documented, after a few months nobody knows why each rule is set the way it is; with every false alarm someone changes the sensitivity at random, and the rule gradually becomes meaningless. Keep a short record for each rule. The values below are entirely illustrative:
rule_id: PERIM-N-03
camera: EXT-CAM-12 (fixed, 4 MP, 6 m mount)
purpose: Detect pedestrian entry into the facility from the north fence
type: line_crossing (double line)
direction: outside -> inside
object_class: person
sensitivity: manufacturer default (50)
schedule: 24/7
excluded_zones: tree line (top left), road (bottom right)
alarm_target: VMS event list + control center audible alert
test_date: 2026-03-10 night / 2026-03-11 day
test_result: 6/6 walking, 4/4 running, 0 false alarms (48 hours)
owner: security operations lead
The test should show two things: the rule catches what it should, and it filters out what it shouldn’t. A minimum test set includes:
- Day and night; normal walking, running, approaching crouched or crawling.
- Crossing in the opposite direction (shouldn’t raise an alarm) and walking parallel to the line.
- Crossing at the far edge of the zone, at the point where the camera’s pixel density is lowest.
- At least 48 hours of passive monitoring in which conditions such as rain, wind and vehicle headlights are observed.
To make detection and false alarm metrics measurable, use the method in the video analytics performance testing article. Tuning a rule after it’s in service is a separate process; we explained it in the false alarm reduction guide.
For rule design, camera placement and test scope in perimeter security, see our perimeter intrusion and virtual fence analytics page, and for the general deployment approach, our AI video analytics deployment page. The starting point for the standards side of analytics event and rule definitions is the ONVIF Profile M document.
Frequently asked questions
Which produces fewer false alarms: line crossing or area intrusion?
Usually area intrusion; the duration threshold filters out momentary errors. Line crossing, on the other hand, is better for perimeter fences where you need to catch the moment of crossing. To reduce false alarms, use double lines, a direction filter and object class together.
Why should a virtual fence line be drawn on the ground?
Most analytics systems evaluate an object by the bottom-center point of its bounding box, that is, foot level. A line not drawn on the ground plane doesn’t match the physical boundary because of perspective; it produces both misses and false alarms.
How is the minimum duration set in an area intrusion rule?
The zone depth is compared with the time it takes the target to cross that depth. The duration should be below the time a running person stays in the zone, but long enough to filter out momentary triggers such as shadows and birds. Verify the value in a pilot.
Should a new rule go straight into alarm mode?
No. A new rule should first run for at least a week in recording-only or event-marking mode, the events it produces should be reviewed in night and day conditions, and only then should it go into alarm mode.