Face Detection & Recognition Camera API
Viewtron AI security cameras include built-in face detection that runs entirely on the camera hardware — no cloud service or external AI software required. When a face is detected in the camera's field of view, the camera sends an HTTP POST webhook to your server with a cropped face image, the full scene image, and face attributes including estimated age, sex, glasses, and mask status.
The camera also supports face recognition (matching) through an on-camera face sample library. When a detected face matches a stored sample, the camera sends a VFD_MATCH event with the match result. Face recognition matching is available on IPC cameras directly — the NVR forwards face detection events (videoFaceDetect) but does not forward match data. 8-channel NVRs support both face detection and face database/recognition, while 4-channel NVRs support face detection only.
What You Can Build
- VIP arrival alerts — detect known faces from a stored library and notify staff when important guests or employees arrive
- Access control integration — grant or deny entry based on face recognition match results
- Demographic analytics — aggregate age and sex attributes across face detections to understand visitor demographics
- Mask compliance monitoring — detect whether people are wearing masks in healthcare or clean room environments
- Face crop archives — save every detected face crop image with timestamp for after-the-fact review
- Multi-camera face tracking — correlate face detections across camera locations by storing and comparing face crops
- Attendance systems — log employee arrivals and departures using face recognition matching
How It Works
- Configure face detection on the camera — enable VFD (Video Face Detection) and set sensitivity and detection zones
- Enable HTTP POST webhooks — point the camera or NVR at your server's IP and port
- Upload face samples (optional) — add face images to the on-camera library for face recognition matching
- Your server receives XML when a face is detected — the POST includes a full scene image, cropped face image, and face attributes
- Parse the event using the Viewtron Python SDK (
pip install viewtron) or Node.js SDK - Take action — save face crops, log attributes to a database, send alerts on recognition matches
Event Data Included
Each face detection webhook POST contains:
| Field | Description |
|---|---|
smartType | VFD (IPC) or videoFaceDetect (NVR) |
targetId | Detection tracking ID |
rect | Face bounding box coordinates (x1, y1, x2, y2) |
age | Age classification: child, young, middleAged, old (NVR v2.0) |
sex | Gender classification: male, female (NVR v2.0) |
glasses | Glasses detection: yes, no, unknown (NVR v2.0) |
mask | Mask detection: yes, no, unknown (NVR v2.0) |
sourceBase64Data | Full scene JPEG image (base64 encoded, ~400-500 KB) |
targetBase64Data | Square face crop JPEG image (base64 encoded, ~10-20 KB, typically 184x184) |
currentTime | Detection timestamp |
Face Recognition (VFD_MATCH) — IPC Only
When a detected face matches a sample in the on-camera library, the IPC sends a VFD_MATCH event with the match result. This event type is IPC only — the NVR does not forward match data.
Face Attribute Values
| Attribute | Possible Values |
|---|---|
age | child, young, middleAged, old |
sex | male, female |
glasses | yes, no, unknown |
mask | yes, no, unknown |
Parsing Face Detection Events
- Python SDK
- Node.js SDK
- NVR XML (v2.0)
- IPC XML (v1.x)
The simplest way to receive face detection 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 != "face":
return
print(f"Face detected from {client_ip}")
# NVR v2.0 includes face attributes
age = event.get_face_age()
sex = event.get_face_sex()
glasses = event.get_face_glasses()
mask = event.get_face_mask()
if age:
print(f" Age: {age}, Sex: {sex}, Glasses: {glasses}, Mask: {mask}")
# Save face crop image
target = event.get_target_image_bytes()
if target:
with open(f"{IMG_DIR}/{event.get_time_stamp()}-face-crop.jpg", "wb") as f:
f.write(target)
# Save full scene image
overview = event.get_source_image_bytes()
if overview:
with open(f"{IMG_DIR}/{event.get_time_stamp()}-face-scene.jpg", "wb") as f:
f.write(overview)
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 !== 'face') return;
console.log(`Face detected from ${clientIP}`);
// NVR v2.0 includes face attributes
if (event.face) {
console.log(` Age: ${event.face.age}, Sex: ${event.face.sex}`);
console.log(` Glasses: ${event.face.glasses}, Mask: ${event.face.mask}`);
}
if (event.targetImageBytes) {
fs.writeFileSync(
`images/${Date.now()}-face-crop.jpg`,
event.targetImageBytes
);
}
if (event.sourceImageBytes) {
fs.writeFileSync(
`images/${Date.now()}-face-scene.jpg`,
event.sourceImageBytes
);
}
});
server.start();
The NVR v2.0 format uses faceListInfo instead of eventInfo + targetListInfo, with face attributes (age, sex, glasses, mask) directly in each item:
<?xml version="1.0" encoding="UTF-8"?>
<config version="2.0.0" xmlns="http://www.ipc.com/ver10">
<messageType>alarmData</messageType>
<deviceInfo>
<deviceName><![CDATA[Front Entrance]]></deviceName>
<ip><![CDATA[192.168.0.60]]></ip>
<mac><![CDATA[58:5B:69:40:F4:0D]]></mac>
<channelId>1</channelId>
</deviceInfo>
<smartType>videoFaceDetect</smartType>
<currentTime>1772212642929000</currentTime>
<sourceDataInfo>
<dataType>0</dataType>
<width>1280</width>
<height>720</height>
<sourceBase64Length>440072</sourceBase64Length>
<sourceBase64Data>... (base64 JPEG overview) ...</sourceBase64Data>
</sourceDataInfo>
<faceListInfo>
<item>
<targetId>50</targetId>
<rect>
<x1>854</x1><y1>176</y1>
<x2>978</x2><y2>300</y2>
</rect>
<age>middleAged</age>
<sex>male</sex>
<glasses>unknown</glasses>
<mask>unknown</mask>
<targetImageData>
<dataType>0</dataType>
<width>184</width>
<height>184</height>
<targetBase64Length>14860</targetBase64Length>
<targetBase64Data>... (base64 JPEG face crop) ...</targetBase64Data>
</targetImageData>
</item>
</faceListInfo>
</config>
See the NVR Event Format reference for the complete v2.0 XML structure.
The IPC v1.x format uses VFD smartType with face crop images in listInfo:
<?xml version="1.0" encoding="UTF-8" ?>
<config version="1.7" xmlns="http://www.ipc.com/ver10">
<smartType type="openAlramObj">VFD</smartType>
<deviceName type="string"><![CDATA[FaceCam]]></deviceName>
<currentTime type="tint64">1774792701902505</currentTime>
<sourceDataInfo>
<sourceBase64Length type="uint32">440072</sourceBase64Length>
<sourceBase64Data type="jpegBase64">... (base64 JPEG scene) ...</sourceBase64Data>
</sourceDataInfo>
<listInfo type="list" count="1">
<item>
<targetImageData>
<targetBase64Length type="uint32">14860</targetBase64Length>
<targetBase64Data type="jpegBase64">... (base64 JPEG face crop) ...</targetBase64Data>
</targetImageData>
</item>
</listInfo>
</config>
Face attributes (age, sex, glasses, mask) are only available in the NVR v2.0 format. The IPC v1.x format includes the face crop image but not the attribute analysis. VFD_MATCH (face recognition) is IPC only — the NVR does not forward match data.
See the IPC Event Format reference for the complete v1.x XML structure.
Face Sample Library
For face recognition (matching), upload face samples to the camera's on-device library. The camera compares detected faces against stored samples and sends VFD_MATCH events when a match is found.
Face library error codes:
| Code | Description |
|---|---|
| 150 | Face library full |
| 151 | Face sample already exists |
| 152 | Face sample not found |
| 153 | Invalid face image format |
| 154 | Face not detected in sample image |
| 155 | Multiple faces in sample image |
| 156 | Face image too small |
| 157 | Face image too blurry |
| 158 | Face library database error |
| 159 | Face library operation timeout |
Face recognition (VFD_MATCH) requires an 8-channel NVR or direct IPC connection. 4-channel NVRs support face detection but not face database/recognition. Even with a face database configured on the NVR, only videoFaceDetect events are forwarded via HTTP Post — match data is not included.
Relevant API Endpoints
| Endpoint | Purpose | Reference |
|---|---|---|
| GetSmartVfdConfig | Read face detection configuration | Face Detection Config |
| SetHttpPostConfig | Configure webhook destination | Webhook Config |
| GetAlarmStatus | Poll current alarm state (vfdAlarm) | Alarm Status |
Integrations
Viewtron face detection also integrates with automation platforms via published packages:
| Platform | Package | What It Does |
|---|---|---|
| Home Assistant | viewtron-home-assistant | Face detection events as native HA sensors for access control automations |
| Node-RED | node-red-contrib-viewtron | Face detection events direct to Node-RED flows — no middleware needed |
Related Applications
- Human Detection & Intrusion Detection — detect people entering zones (body detection, not face)
- People Counting & Traffic Analytics — count people crossing lines or entering areas
- Webhook Event Notification — complete webhook setup and format reference
- Real-Time Object Tracking — continuous target position data via traject
- Viewtron Python SDK — parse face detection events with typed accessors for attributes
Related Products
- Viewtron Face Recognition Cameras — AI camera models with built-in face detection and facial recognition
- Viewtron AI Security Cameras — full AI camera lineup
- Viewtron IP Camera NVRs — NVRs with HTTP POST event forwarding
All face detection processing runs on the camera hardware. There is no cloud API dependency, which is important for deployments that need to comply with facial recognition regulations. The NVR v2.0 format includes face attributes (age, sex, glasses, mask) that the IPC v1.x format does not — see the face detection video demo for a walkthrough of both formats.
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.