1"""Images example of the PST SDK
2
3This example shows how to enable image transfer on the PST Tracker and how to use
4the PST SDK to retrieve images. Images are 8 bit grayscale and are stored as an
5unsigned byte array without memory alignment or padding.
6
7Copyright PS-Tech B.V. All Rights Reserved.
8"""
9import context
10import time
11import sys
14
15
16running = True
17
18
19max_samples = 100
20
21
22samples = 0
23
24"""Implementation of the pst.Listener class to receive tracking data."""
25class MyListener(pst.Listener):
26
27 """Implementation of a tracker data callback function
28
29 Implementation of a tracker data callback function. The on_tracker_data
30 function receives the data as soon as it becomes available.
31
32 Args:
33 tracker_data: Object containing tracking information retrieved from tracker
34 status_message: Status message reported by the tracker.
35
36 See Also:
37 pstech.pstdk.trackerdata.TrackerData
38 pstech.pstsdk.errors.EStatusMessage
39 """
40 def on_tracker_data(self, tracker_data, status_message):
41 global samples
42 global running
43
44 if samples >= max_samples:
45 running = False
46
47 samples += 1
48
49
50"""Helper function to register the exit handler with the application"""
51def register_exit_handler():
52 if sys.platform.startswith("linux"):
53 import signal
54 signal.signal(signal.SIGTERM, exit_handler)
55 signal.signal(signal.SIGHUP, exit_handler)
56 signal.signal(signal.SIGQUIT, exit_handler)
57 signal.signal(signal.SIGINT, exit_handler)
58 elif sys.platform.startswith("win"):
59 import win32api
60 win32api.SetConsoleCtrlHandler(exit_handler, True)
61
62"""Implement the exit handler to shut-down the PST Tracker connection on application termination."""
63def exit_handler(*args):
64 global running
65 pst.Tracker.shutdown()
66 running = False
67 return True
68
69def main():
70 if(len(sys.argv) < 2):
71 print("\nConfiguration Error: A camera configuration file needs to be specified. This file can be found in the Redist folder of your installation. "
72 "See the documentation of the Python bindings for more information.")
73 exit(0)
74
75
76 register_exit_handler()
77
78 try:
79
80
81 with pst.Tracker("", "","", sys.argv[1]) as tracker:
82
83
84 print("Running PST Server version " + tracker.get_version_info())
85
86
87 listener = MyListener()
88
89
90 tracker.add_tracker_listener(listener)
91
92
93 tracker.start()
94
95
96 print("System check: " + str(tracker.system_check()))
97 print("***************************\n")
98
99
100 tracker.set_framerate(60)
101 print("Current frame rate: " + str(tracker.get_framerate()))
102
103
104
105 tracker.enable_image_transfer()
106
107
108
109
110 print("Enabled image transfer. Current frame rate: " + str(tracker.get_framerate()))
111 print("***************************\n")
112
113
114 for i in range(100):
115
116
117
118 image = tracker.get_image()
119
120 if image is not None:
121 print("Retrieval operation successful!\n")
122 print("Retrieved " + str(len(image.images)) + " image(s) of size: " + str(image.width) + " X " + str(image.height) + "\n")
123
124 else:
125 print("Retrieval operation unsuccessful!\n")
126
127
128 time.sleep(0.016)
129
130
131 print("Waiting 5 seconds for image transfer to automatically be disabled...\n")
132 time.sleep(5)
133
134
135 image = tracker.get_image()
136 if image is not None:
137 print("Retrieval operation successful!\n")
138 print("Retrieved " + str(len(image.images)) + " image(s) of size: " + str(image.width) + " X " + str(image.height) + "\n")
139 else:
140 print("Retrieval operation unsuccessful!\n")
141
142 while running:
143 time.sleep(0.1)
144
145 except psterrors.TrackerError as err:
146
147 print(err.message)
148
149if __name__ == "__main__":
150 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