diff options
author | Théo de la Hogue | 2022-04-06 13:50:00 +0200 |
---|---|---|
committer | Théo de la Hogue | 2022-04-06 13:50:00 +0200 |
commit | dfc9765f09f56f63722a446d95e1a61e46b3fb39 (patch) | |
tree | 437258a25a45f31d34e0a710d3ecbfb293bd795c /src | |
parent | 20f79d5ad1e124c7774cfbc9bd7a1abf64da78de (diff) | |
download | argaze-dfc9765f09f56f63722a446d95e1a61e46b3fb39.zip argaze-dfc9765f09f56f63722a446d95e1a61e46b3fb39.tar.gz argaze-dfc9765f09f56f63722a446d95e1a61e46b3fb39.tar.bz2 argaze-dfc9765f09f56f63722a446d95e1a61e46b3fb39.tar.xz |
Fixing data stream capture
Diffstat (limited to 'src')
-rw-r--r-- | src/argaze/TobiiGlassesPro2/TobiiData.py | 32 | ||||
-rw-r--r-- | src/argaze/TobiiGlassesPro2/TobiiVideo.py | 2 | ||||
-rw-r--r-- | src/argaze/utils/live_tobii_session.py | 9 |
3 files changed, 19 insertions, 24 deletions
diff --git a/src/argaze/TobiiGlassesPro2/TobiiData.py b/src/argaze/TobiiGlassesPro2/TobiiData.py index 09afd33..42042ef 100644 --- a/src/argaze/TobiiGlassesPro2/TobiiData.py +++ b/src/argaze/TobiiGlassesPro2/TobiiData.py @@ -21,13 +21,13 @@ class TobiiSegmentData(DataStructures.DictObject): ts_data_buffer_dict = {} # define a decoder function - def decode(json_item): + def decode(json_data): # accept only valid data (e.g. with status value equal to 0) - if json_item.pop('s', -1) == 0: + if json_data.pop('s', -1) == 0: # convert timestamp - ts = json_item.pop('ts') + ts = json_data.pop('ts') # keep first timestamp to offset all timestamps if self.__ts_start == 0: @@ -40,8 +40,8 @@ class TobiiSegmentData(DataStructures.DictObject): return # convert json data into data object - data_object_type = '_'.join(json_item.keys()) - data_object = DataStructures.DictObject(data_object_type, **json_item) + data_object_type = '_'.join(json_data.keys()) + data_object = DataStructures.DictObject(data_object_type, **json_data) # append a dedicated timestamped buffer for each data object type if data_object.get_type() not in ts_data_buffer_dict.keys(): @@ -82,8 +82,6 @@ class TobiiDataStream(threading.Thread): self.__stop_event = threading.Event() self.__read_lock = threading.Lock() - self.__sleep = 1. / self.__network.get_et_freq() - # prepare keep alive message self.__keep_alive_msg = "{\"type\": \"live.data.unicast\", \"key\": \""+ str(uuid.uuid4()) +"\", \"op\": \"start\"}" self.__keep_alive_thread = threading.Thread(target = self.__keep_alive) @@ -124,15 +122,13 @@ class TobiiDataStream(threading.Thread): while not self.__stop_event.isSet(): - # wait - time.sleep(self.__sleep) - # lock data queue access self.__read_lock.acquire() # write in data queue data = self.__network.grab_data(self.__data_socket) - self.__data_queue.put(data) + json_data = json.loads(data.decode('utf-8')) + self.__data_queue.put(json_data) # unlock data queue access self.__read_lock.release() @@ -152,17 +148,15 @@ class TobiiDataStream(threading.Thread): # read data queue while not self.__data_queue.empty(): - data = self.__data_queue.get() - - json_item = json.loads(data.decode('utf-8')) + json_data = self.__data_queue.get() # accept only valid data (e.g. with status value equal to 0) - if json_item.pop('s', -1) == 0: + if json_data.pop('s', -1) == 0: # convert timestamp - ts = json_item.pop('ts') + ts = json_data.pop('ts') - #print(f'json_item at {ts}: {json_item}') + #print(f'json_data at {ts}: {json_data}') ''' # keep first timestamp to offset all timestamps if self.__ts_start == 0: @@ -175,8 +169,8 @@ class TobiiDataStream(threading.Thread): break ''' # convert json data into data object - data_object_type = '_'.join(json_item.keys()) - data_object = DataStructures.DictObject(data_object_type, **json_item) + data_object_type = '_'.join(json_data.keys()) + data_object = DataStructures.DictObject(data_object_type, **json_data) # append a dedicated timestamped buffer for each data object type if data_object.get_type() not in ts_data_buffer_dict.keys(): diff --git a/src/argaze/TobiiGlassesPro2/TobiiVideo.py b/src/argaze/TobiiGlassesPro2/TobiiVideo.py index 748967a..57d64d0 100644 --- a/src/argaze/TobiiGlassesPro2/TobiiVideo.py +++ b/src/argaze/TobiiGlassesPro2/TobiiVideo.py @@ -80,8 +80,6 @@ class TobiiVideoStream(threading.Thread): self.__frame_tuple = None - self.__sleep = 1. / self.__network.get_video_freq() - # prepare keep alive message self.__keep_alive_msg = "{\"type\": \"live.video.unicast\",\"key\": \""+ str(uuid.uuid4()) +"_video\", \"op\": \"start\"}" self.__keep_alive_thread = threading.Timer(0, self.__keep_alive) diff --git a/src/argaze/utils/live_tobii_session.py b/src/argaze/utils/live_tobii_session.py index 0181e23..c78f058 100644 --- a/src/argaze/utils/live_tobii_session.py +++ b/src/argaze/utils/live_tobii_session.py @@ -43,15 +43,18 @@ def main(): video_ts, video_frame = tobii_video_stream.read() try: - + + # read data stream + data_stream = tobii_data_stream.read() + # get last gaze position - last_ts, last_gaze_position = tobii_data_stream.read().gidx_l_gp.pop_last() + last_ts, last_gaze_position = data_stream.gidx_l_gp.pop_last() # Draw tobii gaze pointer pointer = (int(last_gaze_position.gp[0] * video_frame.width), int(last_gaze_position.gp[1] * video_frame.height)) cv.circle(video_frame.matrix, pointer, 4, (0, 255, 255), -1) - # when gidx_l_gp key not received during last frame + # when gidx_l_gp key not in data stream except (KeyError, AttributeError): pass |