diff options
author | Théo de la Hogue | 2024-04-09 00:18:55 +0200 |
---|---|---|
committer | Théo de la Hogue | 2024-04-09 00:18:55 +0200 |
commit | 3edf39d92d14d73f8afd0aaf7f04259cef7455d8 (patch) | |
tree | b6a592a541253dce7d16d032e207d9123cf69648 /src/argaze/utils/contexts/PupilLabs.py | |
parent | ad25274a8493b63c40cd5d59f59889214fcc8aa2 (diff) | |
download | argaze-3edf39d92d14d73f8afd0aaf7f04259cef7455d8.zip argaze-3edf39d92d14d73f8afd0aaf7f04259cef7455d8.tar.gz argaze-3edf39d92d14d73f8afd0aaf7f04259cef7455d8.tar.bz2 argaze-3edf39d92d14d73f8afd0aaf7f04259cef7455d8.tar.xz |
Using https url.
Diffstat (limited to 'src/argaze/utils/contexts/PupilLabs.py')
-rw-r--r-- | src/argaze/utils/contexts/PupilLabs.py | 55 |
1 files changed, 26 insertions, 29 deletions
diff --git a/src/argaze/utils/contexts/PupilLabs.py b/src/argaze/utils/contexts/PupilLabs.py index 43fe47e..d814deb 100644 --- a/src/argaze/utils/contexts/PupilLabs.py +++ b/src/argaze/utils/contexts/PupilLabs.py @@ -1,5 +1,5 @@ """Handle network connection to Pupil Labs devices. Tested with Pupil Invisible. - Based on Pupil Labs' Realtime Python API. + Based on Pupil Labs' Realtime Python API. This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software @@ -9,7 +9,7 @@ This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with -this program. If not, see <http://www.gnu.org/licenses/>. +this program. If not, see <https://www.gnu.org/licenses/>. """ __author__ = "Damien Mouratille" @@ -31,6 +31,7 @@ import cv2 from pupil_labs.realtime_api.simple import discover_one_device + class LiveStream(ArFeatures.ArContext): @DataFeatures.PipelineStepInit @@ -59,75 +60,71 @@ class LiveStream(ArFeatures.ArContext): logging.info('Device found. Stream loading.') # Open gaze stream - self.__gaze_thread = threading.Thread(target = self.__stream_gaze) + self.__gaze_thread = threading.Thread(target=self.__stream_gaze) logging.debug('> starting gaze thread...') self.__gaze_thread.start() - + # Open video stream - self.__video_thread = threading.Thread(target = self.__stream_video) + self.__video_thread = threading.Thread(target=self.__stream_video) logging.debug('> starting video thread...') self.__video_thread.start() - - return self - def __stream_gaze(self): """Stream gaze.""" logging.debug('Stream gaze from Pupil Device') while not self.__stop_event.is_set(): - + try: while True: gaze = self.__device.receive_gaze_datum() gaze_timestamp = int((gaze.timestamp_unix_seconds - self.__start_time) * 1e3) - + logging.debug('Gaze received at %i timestamp', gaze_timestamp) - + # When gaze position is valid if gaze.worn is True: - + self._process_gaze_position( - timestamp = gaze_timestamp, - x = int(gaze.x), - y = int(gaze.y)) + timestamp=gaze_timestamp, + x=int(gaze.x), + y=int(gaze.y)) else: # Process empty gaze position logging.debug('Not worn at %i timestamp', gaze_timestamp) - self._process_gaze_position(timestamp = gaze_timestamp) - + self._process_gaze_position(timestamp=gaze_timestamp) + except KeyboardInterrupt: pass - - + def __stream_video(self): """Stream video.""" logging.debug('Stream video from Pupil Device') while not self.__stop_event.is_set(): - + try: while True: scene_frame, frame_datetime = self.__device.receive_scene_video_frame() - + scene_timestamp = int((frame_datetime - self.__start_time) * 1e3) - + logging.debug('Video received at %i timestamp', scene_timestamp) - + self._process_camera_image( - timestamp = scene_timestamp, - image = scene_frame) - + timestamp=scene_timestamp, + image=scene_frame) + except KeyboardInterrupt: pass @@ -135,10 +132,10 @@ class LiveStream(ArFeatures.ArContext): def __exit__(self, exception_type, exception_value, exception_traceback): logging.debug('Pupil-Labs context stops...') - + # Close data stream self.__stop_event.set() - + # Stop streaming threading.Thread.join(self.__gaze_thread) - threading.Thread.join(self.__video_thread)
\ No newline at end of file + threading.Thread.join(self.__video_thread) |