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 a tracker callback function 41 Implementation of a tracker callback function. The callback_function 42 receives the data as soon as it becomes available. 45 tracker_data: Object containing tracking information retrieved from tracker 46 status_message: Status message reported by the tracker. 49 pstech.pstdk.trackerdata.TrackerData 50 pstech.pstsdk.errors.EStatusMessage 52 def callback_function(tracker_data, status_message):
56 if samples >= max_samples:
62 """Helper function to register the exit handler with the application""" 63 def register_exit_handler():
64 if sys.platform.startswith(
"linux"):
66 signal.signal(signal.SIGTERM, exit_handler)
67 signal.signal(signal.SIGHUP, exit_handler)
68 signal.signal(signal.SIGQUIT, exit_handler)
69 signal.signal(signal.SIGINT, exit_handler)
70 elif sys.platform.startswith(
"win"):
72 win32api.SetConsoleCtrlHandler(exit_handler,
True)
74 """Implement the exit handler to shut-down the PST Tracker connection on application termination.""" 75 def exit_handler(*args):
77 pst.Tracker.shutdown()
82 if(len(sys.argv) < 2):
83 print(
"\nConfiguration Error: A camera configuration file needs to be specified. This file can be found in the Redist folder of your installation. " 84 "See the documentation of the Python bindings for more information.")
88 register_exit_handler()
93 with pst.Tracker(
"",
"",
"", sys.argv[1])
as tracker:
95 print(
"Running PST Server version " + tracker.get_version_info())
98 tracker.add_tracker_listener(callback_function)
104 print(
"System check: " + str(tracker.system_check()))
107 tracker.set_framerate(30)
111 print(
"Frame rate set to: " + str(tracker.get_framerate()))
112 print(
"***************************\n")
115 print(
"Current reference system transformation matrix:")
116 print_matrix(tracker.get_reference())
122 reference = [-1.0, 0.0, 0.0, 0.1,
127 tracker.set_reference(reference)
128 print(
"New reference system transformation matrix:")
129 print_matrix(tracker.get_reference())
133 non_orthonormal_reference = [-1.0, 1.0, 0.0, 0.1,
138 tracker.set_reference(non_orthonormal_reference)
139 print(
"New reference system after applying non-orthonormal transformation:")
140 print_matrix(tracker.get_reference())
144 relative_reference = [ 0.0,-1.0, 0.0, 0.5,
149 tracker.set_reference(relative_reference,
True)
150 print(
"New reference system after applying relative transformation:")
151 print_matrix(tracker.get_reference())
152 print(
"***************************\n")
156 tracker.set_default_reference()
157 print(
"Reset default reference system:")
158 print_matrix(tracker.get_reference())
163 except psterrors.TrackerError
as err:
167 if __name__ ==
"__main__":