1 """Tracking target example of the PST SDK
3 This example shows how to work with tracking targets using the PST SDK.
4 Note that at this moment tracking targets can not be trained or
5 imported using the PST SDK. In order to add new tracking targets, please
6 use the PST Client together with the pstech.pstsdk.tracker.Tracker.enable_shared_memory()
7 function, or use the stand-alone PST Server to configure the tracking targets.
9 Copyright PS-Tech B.V. All Rights Reserved.
26 """Implementation of the pst.Listener class to receive tracking data and mode changes."""
27 class MyListener(pst.Listener):
29 """Implementation of a tracker data callback function
31 Implementation of a tracker data callback function. The on_tracker_data
32 function receives the data as soon as it becomes available.
35 tracker_data: Object containing tracking information retrieved from tracker
36 status_message: Status message reported by the tracker.
39 pstech.pstdk.trackerdata.TrackerData
40 pstech.pstsdk.errors.EStatusMessage
42 def on_tracker_data(self, tracker_data, status_message):
47 if samples >= max_samples:
50 for target_pose
in tracker_data.targetlist:
51 print(
"Detected " + target_pose.name)
55 """Helper function to register the exit handler with the application"""
56 def register_exit_handler():
57 if sys.platform.startswith(
"linux"):
59 signal.signal(signal.SIGTERM, exit_handler)
60 signal.signal(signal.SIGHUP, exit_handler)
61 signal.signal(signal.SIGQUIT, exit_handler)
62 signal.signal(signal.SIGINT, exit_handler)
63 elif sys.platform.startswith(
"win"):
65 win32api.SetConsoleCtrlHandler(exit_handler,
True)
67 """Implement the exit handler to shut-down the PST Tracker connection on application termination."""
68 def exit_handler(*args):
70 pst.Tracker.shutdown()
75 if(len(sys.argv) < 2):
76 print(
"\nConfiguration Error: A camera configuration file needs to be specified. This file can be found in the Redist folder of your installation. "
77 "See the documentation of the Python bindings for more information.")
81 register_exit_handler()
86 with pst.Tracker(
"",
"",
"", sys.argv[1])
as tracker:
89 print(
"Running PST Server version " + tracker.get_version_info())
92 listener = MyListener()
95 tracker.add_tracker_listener(listener)
97 print(
"Put the Reference card in front of the PST in order to see tracking results.\n")
103 print(
"System check: " + str(tracker.system_check()))
106 targets = tracker.get_target_list()
107 print(
"Found " + str(len(targets)) +
" tracking targets:")
108 for target_status
in targets:
109 print(target_status.name +
"\t" + str(target_status.status))
114 tracker.set_target_status(
"Reference",
True)
118 markers_list = tracker.get_target_markers(
"Reference")
119 print(
"3D marker positions making up the Reference target:")
120 for marker
in markers_list:
121 print(
"x: " + str(marker[0]) +
"\ty: " + str(marker[1]) +
"\tz: " + str(marker[2]))
128 except psterrors.TrackerError
as err:
132 if __name__ ==
"__main__":