From 3edf39d92d14d73f8afd0aaf7f04259cef7455d8 Mon Sep 17 00:00:00 2001 From: Théo de la Hogue Date: Tue, 9 Apr 2024 00:18:55 +0200 Subject: Using https url. --- src/argaze/utils/contexts/PupilLabs.py | 55 ++++++++++++++++------------------ 1 file changed, 26 insertions(+), 29 deletions(-) (limited to 'src/argaze/utils/contexts/PupilLabs.py') 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 . +this program. If not, see . """ __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) -- cgit v1.1