1 """Reference example of the PST SDK 3 This example shows how to use the PST SDK to adjust the PST Tracker reference system. 4 The reference system defines the Cartesian coordinate system in which tracking results 5 are reported. The example shows how to set the reference system by supplying a 4x4 6 homogeneous transformation matrix. It also shows how to check if the reference system 9 Copyright PS-Tech B.V. All Rights Reserved. 22 """Helper function for printing """ 23 def print_matrix(matrix):
26 print(str(matrix[x + y * 4]), end=
"\t")
39 """Implementation of the pst.Listener class to receive tracking data and mode changes.""" 40 class MyListener(pst.Listener):
42 """Implementation of a tracker data callback function 44 Implementation of a tracker data callback function. The on_tracker_data 45 function receives the data as soon as it becomes available. 48 tracker_data: Object containing tracking information retrieved from tracker 49 status_message: Status message reported by the tracker. 52 pstech.pstdk.trackerdata.TrackerData 53 pstech.pstsdk.errors.EStatusMessage 55 def on_tracker_data(self, tracker_data, status_message):
59 if samples >= max_samples:
65 """Helper function to register the exit handler with the application""" 66 def register_exit_handler():
67 if sys.platform.startswith(
"linux"):
69 signal.signal(signal.SIGTERM, exit_handler)
70 signal.signal(signal.SIGHUP, exit_handler)
71 signal.signal(signal.SIGQUIT, exit_handler)
72 signal.signal(signal.SIGINT, exit_handler)
73 elif sys.platform.startswith(
"win"):
75 win32api.SetConsoleCtrlHandler(exit_handler,
True)
77 """Implement the exit handler to shut-down the PST Tracker connection on application termination.""" 78 def exit_handler(*args):
80 pst.Tracker.shutdown()
85 if(len(sys.argv) < 2):
86 print(
"\nConfiguration Error: A camera configuration file needs to be specified. This file can be found in the Redist folder of your installation. " 87 "See the documentation of the Python bindings for more information.")
91 register_exit_handler()
96 with pst.Tracker(
"",
"",
"", sys.argv[1])
as tracker:
98 print(
"Running PST Server version " + tracker.get_version_info())
101 listener = MyListener()
104 tracker.add_tracker_listener(listener)
110 print(
"System check: " + str(tracker.system_check()))
113 tracker.set_framerate(30)
117 print(
"Frame rate set to: " + str(tracker.get_framerate()))
118 print(
"***************************\n")
121 print(
"Current reference system transformation matrix:")
122 print_matrix(tracker.get_reference())
128 reference = [-1.0, 0.0, 0.0, 0.1,
133 tracker.set_reference(reference)
134 print(
"New reference system transformation matrix:")
135 print_matrix(tracker.get_reference())
139 non_orthonormal_reference = [-1.0, 1.0, 0.0, 0.1,
145 tracker.set_reference(non_orthonormal_reference)
146 print(
"Reference input incorrectly applied!")
147 except psterrors.TrackerError
as err:
149 print(
"Reference input correctly ignored: %s" % err.message)
150 print(
"New reference system after applying non-orthonormal transformation:")
151 print_matrix(tracker.get_reference())
155 relative_reference = [ 0.0,-1.0, 0.0, 0.5,
160 tracker.set_reference(relative_reference,
True)
161 print(
"New reference system after applying relative transformation:")
162 print_matrix(tracker.get_reference())
163 print(
"***************************\n")
167 tracker.set_default_reference()
168 print(
"Reset default reference system:")
169 print_matrix(tracker.get_reference())
174 except psterrors.TrackerError
as err:
178 if __name__ ==
"__main__":