Skip to main content

Images

Overview

Most Viewtron camera events include snapshot images — a source image (full camera view at the time of detection) and optionally a target image (cropped area of the detected object). Images are JPEG format, embedded as base64 in the XML payload.

Image Methods

Available on all event objects (LPR, Face, Intrusion, Counting):

MethodReturnsDescription
source_image_exists()boolWhether a source (overview) image is attached
target_image_exists()boolWhether a target (cropped) image is attached
images_exist()boolWhether any images are attached
get_source_image()str or NoneBase64-encoded source image
get_target_image()str or NoneBase64-encoded target image
get_source_image_bytes()bytes or NoneDecoded JPEG bytes for source image
get_target_image_bytes()bytes or NoneDecoded JPEG bytes for target image

Source vs Target Images

Image TypeWhat It ContainsTypical Use
Source imageFull camera view at the moment of detectionScene context, recording, human review
Target imageCropped region of the detected objectFace crops, plate crops, object identification

When Images Are Included

Event TypeSource ImageTarget Image
LPRYes — full sceneYes — cropped plate
Face DetectionYes — full sceneYes — cropped face
IntrusionYes — full sceneSometimes
CountingSometimesRarely
TrajectNoNo

Image availability depends on camera model and configuration. Always check source_image_exists() / target_image_exists() before accessing.

Code Examples

Saving Images to Disk

def handle_event(event, client_ip):
timestamp = event.get_time_stamp()
category = event.category

if event.source_image_exists():
with open(f"{category}_{timestamp}_source.jpg", "wb") as f:
f.write(event.get_source_image_bytes())

if event.target_image_exists():
with open(f"{category}_{timestamp}_target.jpg", "wb") as f:
f.write(event.get_target_image_bytes())

Sending via MQTT

import paho.mqtt.client as mqtt

mqtt_client = mqtt.Client()
mqtt_client.connect("localhost", 1883)

def handle_event(event, client_ip):
if event.category == "lpr" and event.source_image_exists():
# Publish raw JPEG bytes
mqtt_client.publish(
"camera/lpr/image",
event.get_source_image_bytes()
)

Base64 for Web/API

import json

def handle_event(event, client_ip):
if event.category == "face" and event.target_image_exists():
# Base64 string ready for JSON or HTML <img> tags
face_b64 = event.get_target_image()

payload = json.dumps({
"camera": event.get_ip_cam(),
"face_image": face_b64
})
# Send to your API, embed in HTML as data:image/jpeg;base64,...

Checking Before Accessing

def handle_event(event, client_ip):
if not event.images_exist():
print(f"No images in {event.category} event")
return

if event.source_image_exists():
source_bytes = event.get_source_image_bytes()
print(f"Source image: {len(source_bytes)} bytes")

if event.target_image_exists():
target_bytes = event.get_target_image_bytes()
print(f"Target image: {len(target_bytes)} bytes")

Image Sizes

Typical image sizes vary by camera resolution and model:

  • Source images: 50KB-500KB (full resolution camera snapshot)
  • Target images: 5KB-50KB (cropped region)

These are embedded in the XML payload, so events with images are significantly larger than events without.