1"""Tracking target example of the PST SDK
2
3This example shows how to work with tracking targets using the PST SDK.
4Note that at this moment tracking targets can not be trained or
5imported using the PST SDK. In order to add new tracking targets, please
6use the PST Client together with the pstech.pstsdk.tracker.Tracker.enable_shared_memory()
7function, or use the stand-alone PST Server to configure the tracking targets.
8
9Copyright PS-Tech B.V. All Rights Reserved.
10"""
11import context
12import time
13import sys
16
17
18running = True
19
20
21max_samples = 100
22
23
24samples = 0
25
26"""Implementation of the pst.Listener class to receive tracking data and mode changes."""
27class MyListener(pst.Listener):
28
29 """Implementation of a tracker data callback function
30
31 Implementation of a tracker data callback function. The on_tracker_data
32 function receives the data as soon as it becomes available.
33
34 Args:
35 tracker_data: Object containing tracking information retrieved from tracker
36 status_message: Status message reported by the tracker.
37
38 See Also:
39 pstech.pstdk.trackerdata.TrackerData
40 pstech.pstsdk.errors.EStatusMessage
41 """
42 def on_tracker_data(self, tracker_data, status_message):
43
44 global samples
45 global running
46
47 if samples >= max_samples:
48 running = False
49
50 for target_pose in tracker_data.targetlist:
51 print("Detected " + target_pose.name)
52
53 samples += 1
54
55"""Helper function to register the exit handler with the application"""
56def register_exit_handler():
57 if sys.platform.startswith("linux"):
58 import signal
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"):
64 import win32api
65 win32api.SetConsoleCtrlHandler(exit_handler, True)
66
67"""Implement the exit handler to shut-down the PST Tracker connection on application termination."""
68def exit_handler(*args):
69 global running
70 pst.Tracker.shutdown()
71 running = False
72 return True
73
74def main():
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.")
78 exit(0)
79
80
81 register_exit_handler()
82
83 try:
84
85
86 with pst.Tracker("", "","", sys.argv[1]) as tracker:
87
88
89 print("Running PST Server version " + tracker.get_version_info())
90
91
92 listener = MyListener()
93
94
95 tracker.add_tracker_listener(listener)
96
97 print("Put the Reference card in front of the PST in order to see tracking results.\n")
98
99
100 tracker.start()
101
102
103 print("System check: " + str(tracker.system_check()))
104
105
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))
110 print("")
111
112
113
114 tracker.set_target_status("Reference", True)
115
116
117
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]))
122 print("")
123
124
125 while running:
126 time.sleep(0.1)
127
128 except psterrors.TrackerError as err:
129
130 print(err.message)
131
132if __name__ == "__main__":
133 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