1 """Images example of the PST SDK 3 This example shows how to enable image transfer on the PST Tracker and how to use 4 the PST SDK to retrieve images. Images are 8 bit grayscale and are stored as an 5 unsigned byte array without memory alignment or padding. 7 Copyright PS-Tech B.V. All Rights Reserved. 24 """Implementation of the pst.Listener class to receive tracking data.""" 25 class MyListener(pst.Listener):
27 """Implementation of a tracker data callback function 29 Implementation of a tracker data callback function. The on_tracker_data 30 function receives the data as soon as it becomes available. 33 tracker_data: Object containing tracking information retrieved from tracker 34 status_message: Status message reported by the tracker. 37 pstech.pstdk.trackerdata.TrackerData 38 pstech.pstsdk.errors.EStatusMessage 40 def on_tracker_data(self, tracker_data, status_message):
44 if samples >= max_samples:
50 """Helper function to register the exit handler with the application""" 51 def register_exit_handler():
52 if sys.platform.startswith(
"linux"):
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"):
60 win32api.SetConsoleCtrlHandler(exit_handler,
True)
62 """Implement the exit handler to shut-down the PST Tracker connection on application termination.""" 63 def exit_handler(*args):
65 pst.Tracker.shutdown()
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.")
76 register_exit_handler()
81 with pst.Tracker(
"",
"",
"", sys.argv[1])
as tracker:
84 print(
"Running PST Server version " + tracker.get_version_info())
87 listener = MyListener()
90 tracker.add_tracker_listener(listener)
96 print(
"System check: " + str(tracker.system_check()))
97 print(
"***************************\n")
100 tracker.set_framerate(60)
101 print(
"Current frame rate: " + str(tracker.get_framerate()))
105 tracker.enable_image_transfer()
110 print(
"Enabled image transfer. Current frame rate: " + str(tracker.get_framerate()))
111 print(
"***************************\n")
118 image = tracker.get_image()
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")
125 print(
"Retrieval operation unsuccessful!\n")
131 print(
"Waiting 5 seconds for image transfer to automatically be disabled...\n")
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")
140 print(
"Retrieval operation unsuccessful!\n")
145 except psterrors.TrackerError
as err:
149 if __name__ ==
"__main__":