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 a tracker callback function 26 Implementation of a tracker callback function. The callback_function 27 receives the data as soon as it becomes available. 30 tracker_data: Object containing tracking information retrieved from tracker 31 status_message: Status message reported by the tracker. 34 pstech.pstdk.trackerdata.TrackerData 35 pstech.pstsdk.errors.EStatusMessage 37 def callback_function(tracker_data, status_message):
41 if samples >= max_samples:
47 """Helper function to register the exit handler with the application""" 48 def register_exit_handler():
49 if sys.platform.startswith(
"linux"):
51 signal.signal(signal.SIGTERM, exit_handler)
52 signal.signal(signal.SIGHUP, exit_handler)
53 signal.signal(signal.SIGQUIT, exit_handler)
54 signal.signal(signal.SIGINT, exit_handler)
55 elif sys.platform.startswith(
"win"):
57 win32api.SetConsoleCtrlHandler(exit_handler,
True)
59 """Implement the exit handler to shut-down the PST Tracker connection on application termination.""" 60 def exit_handler(*args):
62 pst.Tracker.shutdown()
67 if(len(sys.argv) < 2):
68 print(
"\nConfiguration Error: A camera configuration file needs to be specified. This file can be found in the Redist folder of your installation. " 69 "See the documentation of the Python bindings for more information.")
73 register_exit_handler()
78 with pst.Tracker(
"",
"",
"", sys.argv[1])
as tracker:
81 print(
"Running PST Server version " + tracker.get_version_info())
84 tracker.add_tracker_listener(callback_function)
90 print(
"System check: " + str(tracker.system_check()))
91 print(
"***************************\n")
94 tracker.set_framerate(60)
95 print(
"Current frame rate: " + str(tracker.get_framerate()))
99 tracker.enable_image_transfer()
104 print(
"Enabled image transfer. Current frame rate: " + str(tracker.get_framerate()))
105 print(
"***************************\n")
112 image = tracker.get_image()
114 if image
is not None:
115 print(
"Retrieval operation successful!\n")
116 print(
"Retrieved " + str(len(image.images)) +
" image(s) of size: " + str(image.width) +
" X " + str(image.height) +
"\n")
119 print(
"Retrieval operation unsuccessful!\n")
125 print(
"Waiting 5 seconds for image transfer to automatically be disabled...\n")
129 image = tracker.get_image()
130 if image
is not None:
131 print(
"Retrieval operation successful!\n")
132 print(
"Retrieved " + str(len(image.images)) +
" image(s) of size: " + str(image.width) +
" X " + str(image.height) +
"\n")
134 print(
"Retrieval operation unsuccessful!\n")
139 except psterrors.TrackerError
as err:
143 if __name__ ==
"__main__":