PST SDK  5.2.0.0-0eac0f6
minimal.py
1 """Minimal example of the PST SDK
2 
3 This is a bare minimum example showing how to connect to the PST SDK and how to
4 register a listener to receive data.
5 
6 In order to be able to run this example, the PST Tracker has to be initialized first.
7 This can be done by starting the PST-Server and the PST-Client application and making
8 sure the calibration files have been downloaded and a tracking target is available.
9 The tracking target can be the default Reference target or a newly trained or imported
10 target. For more information, please see the Initialization section of the PST SDK manual
11 or check the PST Manual.
12 
13 Copyright PS-Tech B.V. All Rights Reserved.
14 """
15 import context
16 import time
17 import sys
18 import pstech.pstsdk.tracker as pst
19 import pstech.pstsdk.errors as psterrors
20 
21 """Implementation of a tracker callback function
22 
23 Implementation of a tracker callback function. The callback_function
24 receives the data as soon as it becomes available.
25 
26 Args:
27  tracker_data: Object containing tracking information retrieved from tracker
28  status_message: Status message reported by the tracker.
29 
30 See Also:
31  pstech.pstdk.trackerdata.TrackerData
32  pstech.pstsdk.errors.EStatusMessage
33 """
34 def callback_function(tracker_data, status_message: int):
35  # Do something with the tracker data
36  pass
37 
38 def main():
39  if(len(sys.argv) < 2):
40  print("\nConfiguration Error: A camera configuration file needs to be specified. This file can be found in the Redist folder of your installation. "
41  "See the documentation of the Python bindings for more information.")
42  exit(0)
43 
44  try:
45  # Use Context Manager to prevent improper Tracker shutdown on errors.
46  # Create an instance of the Tracker object using the default configuration path and file names.
47  with pst.Tracker("", "","", sys.argv[1]) as tracker:
48  # Register the listener object to the tracker server.
49  tracker.add_tracker_listener(callback_function)
50 
51  # Start the tracker server.
52  tracker.start()
53 
54  # Wait for 10 seconds, allowing for the detection of tracking targets.
55  time.sleep(10)
56  except psterrors.TrackerError as err:
57  # Catch TrackerError and print error messages.
58  print(err.message)
59 
60 if __name__ == "__main__":
61  main()