Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
123 changes: 123 additions & 0 deletions examples/thermal_example.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
#!/usr/bin/env python3
"""
Example script demonstrating ONVIF Thermal Service usage.

This script shows how to:
1. Connect to an ONVIF camera
2. Create a thermal service
3. Get thermal service capabilities
4. Get thermal configuration options
5. Get and set thermal configuration
6. Get and set radiometry configuration

Usage:
python thermal_example.py <host> <port> <username> <password>

Example:
python thermal_example.py 192.168.1.100 80 admin password123
"""

import sys
import os

# Add the parent directory to the path so we can import the onvif module
sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))

from onvif import ONVIFCamera


def main():
if len(sys.argv) != 5:
print("Usage: python thermal_example.py <host> <port> <username> <password>")
sys.exit(1)

host = sys.argv[1]
port = int(sys.argv[2])
username = sys.argv[3]
password = sys.argv[4]

try:
# Create ONVIF camera instance
print(f"Connecting to camera at {host}:{port}...")
cam = ONVIFCamera(host, port, username, password)

# Create thermal service
print("Creating thermal service...")
thermal_service = cam.create_thermal_service()

# Get thermal service capabilities
print("\n=== Thermal Service Capabilities ===")
try:
capabilities = thermal_service.GetServiceCapabilities()
print(f"Radiometry supported: {capabilities.Capabilities.Radiometry}")
except Exception as e:
print(f"Error getting capabilities: {e}")

# Get thermal configuration options
print("\n=== Thermal Configuration Options ===")
try:
# You'll need to get a video source token first
# This is just an example - you might need to get this from media service
video_source_token = "your_video_source_token_here" # Replace with actual token

config_options = thermal_service.GetConfigurationOptions({
'VideoSourceToken': video_source_token
})
print("Configuration options retrieved successfully")
print(f"Available color palettes: {len(config_options.ConfigurationOptions.ColorPalette)}")

if hasattr(config_options.ConfigurationOptions, 'NUCTable'):
print(f"Available NUC tables: {len(config_options.ConfigurationOptions.NUCTable)}")

if hasattr(config_options.ConfigurationOptions, 'CoolerOptions'):
print("Cooler options available")

except Exception as e:
print(f"Error getting configuration options: {e}")

# Get thermal configuration
print("\n=== Current Thermal Configuration ===")
try:
config = thermal_service.GetConfiguration({
'VideoSourceToken': video_source_token
})
print("Current thermal configuration retrieved successfully")
print(f"Color palette: {config.Configuration.ColorPalette.Name}")
print(f"Polarity: {config.Configuration.Polarity}")

except Exception as e:
print(f"Error getting configuration: {e}")

# Get radiometry configuration options
print("\n=== Radiometry Configuration Options ===")
try:
radiometry_options = thermal_service.GetRadiometryConfigurationOptions({
'VideoSourceToken': video_source_token
})
print("Radiometry configuration options retrieved successfully")

except Exception as e:
print(f"Error getting radiometry options: {e}")

# Get radiometry configuration
print("\n=== Current Radiometry Configuration ===")
try:
radiometry_config = thermal_service.GetRadiometryConfiguration({
'VideoSourceToken': video_source_token
})
print("Current radiometry configuration retrieved successfully")

except Exception as e:
print(f"Error getting radiometry configuration: {e}")

print("\n=== Example completed ===")
print("Note: Some operations may fail if the camera doesn't support thermal features")
print("or if the video source token is not valid.")

except Exception as e:
print(f"Error: {e}")
sys.exit(1)


if __name__ == "__main__":
main()
8 changes: 6 additions & 2 deletions onvif/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ def __init__(self, xaddr, user, passwd, url,
self.zeep_client.set_ns_prefix('tptz', 'http://www.onvif.org/ver20/ptz/wsdl')
self.zeep_client.set_ns_prefix('ttr', 'http://www.onvif.org/ver10/media/wsdl')
self.zeep_client.set_ns_prefix('ter', 'http://www.onvif.org/ver10/error')
self.zeep_client.set_ns_prefix('tth', 'http://www.onvif.org/ver10/thermal/wsdl')
else:
self.zeep_client = zeep_client
self.ws_client = self.zeep_client.create_service(binding_name, self.xaddr)
Expand Down Expand Up @@ -192,9 +193,9 @@ class ONVIFCamera(object):

# Class-level variables
services_template = {'devicemgmt': None, 'ptz': None, 'media': None,
'imaging': None, 'events': None, 'analytics': None}
'imaging': None, 'events': None, 'analytics': None, 'thermal': None}
use_services_template = {'devicemgmt': True, 'ptz': True, 'media': True,
'imaging': True, 'events': True, 'analytics': True}
'imaging': True, 'events': True, 'analytics': True, 'thermal': True}

def __init__(self, host, port, user, passwd,
wsdl_dir=os.path.join(os.path.dirname(__file__),
Expand Down Expand Up @@ -403,3 +404,6 @@ def create_notification_service(self, transport=None):

def create_subscription_service(self, transport=None):
return self.create_onvif_service('subscription', transport=transport)

def create_thermal_service(self, transport=None):
return self.create_onvif_service('thermal', transport=transport)
1 change: 1 addition & 0 deletions onvif/definition.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
'events' : {'ns': 'http://www.onvif.org/ver10/events/wsdl', 'wsdl': 'events.wsdl', 'binding' : 'EventBinding'},
'pullpoint' : {'ns': 'http://www.onvif.org/ver10/events/wsdl', 'wsdl': 'events.wsdl', 'binding' : 'PullPointSubscriptionBinding'},
'notification' : {'ns': 'http://www.onvif.org/ver10/events/wsdl', 'wsdl': 'events.wsdl', 'binding' : 'NotificationProducerBinding'},
'thermal' : {'ns': 'http://www.onvif.org/ver10/thermal/wsdl', 'wsdl': 'thermal.wsdl', 'binding' : 'ThermalBinding'},
'subscription' : {'ns': 'http://www.onvif.org/ver10/events/wsdl', 'wsdl': 'events.wsdl', 'binding' : 'SubscriptionManagerBinding'},
'analytics' : {'ns': 'http://www.onvif.org/ver20/analytics/wsdl', 'wsdl': 'analytics.wsdl', 'binding' : 'AnalyticsEngineBinding'},
'recording' : {'ns': 'http://www.onvif.org/ver10/recording/wsdl', 'wsdl': 'recording.wsdl', 'binding' : 'RecordingBinding'},
Expand Down
Loading