1"""Exposure example of the PST SDK
2
3This example shows how to adjust exposure settings using the PST SDK. It shows how to
4change exposure settings based on frame rate and the available exposure range for a
5certain PST Tracker at a certain frame rate.
6
7Copyright PS-Tech B.V. All Rights Reserved.
8"""
9import context
10import time
11import sys
14
15
16running = True
17
18
19max_samples = 100
20
21
22samples = 0
23
24"""Implementation of the pst.Listener class to receive tracking data."""
25class MyListener(pst.Listener):
26
27 """Implementation of a tracker data callback function
28
29 Implementation of a tracker data callback function. The on_tracker_data
30 function receives the data as soon as it becomes available.
31
32 Args:
33 tracker_data: Object containing tracking information retrieved from tracker
34 status_message: Status message reported by the tracker.
35
36 See Also:
37 pstech.pstdk.trackerdata.TrackerData
38 pstech.pstsdk.errors.EStatusMessage
39 """
40 def on_tracker_data(self, tracker_data, status_message):
41 global samples
42 global running
43
44 if samples >= max_samples:
45 running = False
46
47 samples += 1
48
49
50"""Helper function to register the exit handler with the application"""
51def register_exit_handler():
52 if sys.platform.startswith("linux"):
53 import signal
54 signal.signal(signal.SIGTERM, exit_handler)
55 signal.signal(signal.SIGHUP, exit_handler)
56 signal.signal(signal.SIGQUIT, exit_handler)
57 signal.signal(signal.SIGINT, exit_handler)
58 elif sys.platform.startswith("win"):
59 import win32api
60 win32api.SetConsoleCtrlHandler(exit_handler, True)
61
62
63"""Implement the exit handler to shut-down the PST Tracker connection on application termination."""
64def exit_handler(*args):
65 global running
66 pst.Tracker.shutdown()
67 running = False
68 return True
69
70def main():
71 if(len(sys.argv) < 2):
72 print("\nConfiguration Error: A camera configuration file needs to be specified. This file can be found in the Redist folder of your installation. "
73 "See the documentation of the Python bindings for more information.")
74 exit(0)
75
76
77 register_exit_handler()
78
79 try:
80
81
82 with pst.Tracker("", "","", sys.argv[1]) as tracker:
83
84
85 print("Running PST Server version " + tracker.get_version_info())
86
87
88 listener = MyListener()
89
90
91 tracker.add_tracker_listener(listener)
92
93
94 tracker.start()
95
96
97 print("System check: " + str(tracker.system_check()))
98 print("***************************\n")
99
100
101 tracker.set_framerate(30)
102
103
104
105 print("Frame rate set to: " + str(tracker.get_framerate()) + " Hz\n")
106
107
108 min, max = tracker.get_exposure_range()
109 print("Exposure range: " + str(min) + " s - " + str(max) + " s")
110 print("Set Exposure to " + str(max))
111 tracker.set_exposure(max)
112 print("Check new exposure: " + str(tracker.get_exposure()) + " s")
113 print("***************************\n")
114
115
116
117
118 print("Set frame rate to 60 Hz")
119 tracker.set_framerate(60)
120 print("Frame rate set to: " + str(tracker.get_framerate()) + " Hz\n")
121 print("Check exposure: " + str(tracker.get_exposure()) + " s")
122
123
124 min, max = tracker.get_exposure_range()
125 print("New exposure range: " + str(min) + " s - " + str(max) + " s")
126 print("***************************\n")
127
128
129 exposure_half = min + (max - min) / 2.0
130 print("Set exposure half way: " + str(exposure_half) + " s")
131 tracker.set_exposure(exposure_half)
132 print("Check new exposure: " + str(tracker.get_exposure()) + " s")
133 print("***************************\n")
134
135 while running:
136 time.sleep(0.1)
137
138 except psterrors.TrackerError as err:
139
140 print(err.message)
141
142if __name__ == "__main__":
143 main()
Module containing all error related classes and functions.
Definition errors.py:1
Module containing all tracker related classes and functions.
Definition tracker.py:1