1 """Listener example of the PST SDK 3 This example shows how to implement the PST SDK using the Tracker class 4 and how to receive data by implementing a callback function. The example 5 initializes the PST Tracker and grabs 100 data points. 7 In order to be able to run this example, the PST Tracker has to be initialized first. 8 This can be done by starting the PST-Server and the PST-Client application and making 9 sure the calibration files have been downloaded and a tracking target is available. 10 The tracking target can be the default Reference target or a newly trained or imported 11 target. For more information, please see the Initialization section of the PST SDK manual 12 or check the PST Manual. 14 Copyright PS-Tech B.V. All Rights Reserved. 31 """Helper function for clear printing of 4x4 matrices.""" 32 def print_matrix(matrix):
36 print(str(matrix[x + y * 4]), end=
"\t")
40 """Implementation of a tracker callback function 42 Implementation of a tracker callback function. The callback_function 43 receives the data as soon as it becomes available and prints the tracking 44 target pose to the command line. 47 tracker_data: Object containing tracking information retrieved from tracker 48 status_message: Status message reported by the tracker. 51 pstech.pstdk.trackerdata.TrackerData 52 pstech.pstsdk.errors.EStatusMessage 54 def callback_function(tracker_data, status_message):
58 if samples >= max_samples:
61 if len(tracker_data.targetlist) > 0:
62 for target_pose
in tracker_data.targetlist:
63 print(
"Pose for " + target_pose.name)
64 print_matrix(target_pose.pose)
68 """Helper function to register the exit handler with the application""" 69 def register_exit_handler():
70 if sys.platform.startswith(
"linux"):
72 signal.signal(signal.SIGTERM, exit_handler)
73 signal.signal(signal.SIGHUP, exit_handler)
74 signal.signal(signal.SIGQUIT, exit_handler)
75 signal.signal(signal.SIGINT, exit_handler)
76 elif sys.platform.startswith(
"win"):
78 win32api.SetConsoleCtrlHandler(exit_handler,
True)
80 """Implement the exit handler to shut-down the PST Tracker connection on application termination.""" 81 def exit_handler(*args):
83 pst.Tracker.shutdown()
88 if(len(sys.argv) < 2):
89 print(
"\nConfiguration Error: A camera configuration file needs to be specified. This file can be found in the Redist folder of your installation. " 90 "See the documentation of the Python bindings for more information.")
94 register_exit_handler()
99 with pst.Tracker(
"",
"",
"", sys.argv[1])
as tracker:
102 if(len(tracker.get_uncalibrated_camera_urls()) > 0):
103 print(
"\nNo calibration information could be found in the configuration directory.\n" 104 "Please use the PST Server and PST Client application to initialize the PST Tracker and create/import a tracking target.\n" 105 "More information can be found in the Initialization section of the PST SDK manual and the PST Manual.\n" 110 print(
"Running PST Server version " + tracker.get_version_info())
113 tracker.add_tracker_listener(callback_function)
115 print(
"Put the Reference card in front of the PST in order to see tracking results.\n")
121 print(
"System check: " + str(tracker.system_check()))
124 tracker.set_framerate(30)
129 print(
"Frame rate set to: " + str(tracker.get_framerate()))
135 except psterrors.TrackerError
as err:
139 if __name__ ==
"__main__":