ddetommaso / TobiiGlassesPySuite

A Python based software suite for designing eye-tracking studies with the Tobii Pro Glasses 2
GNU General Public License v3.0
14 stars 8 forks source link

About video-gaze mapping procedure #4

Open ajdroid opened 4 years ago

ajdroid commented 4 years ago

In video.py, the VideoFramesAndMappedGaze does sync in this way:

T = self.__df__.index[self.__df__.index.get_loc(self.__current_time__+self.__i__, method='nearest')]

As I understand it, current_time is the current frame's ts and you are finding the nearest ts in the gaze data. Here, why is the i counter being added to current_time?

ajdroid commented 4 years ago

I think one way to solve this would be (keep current time in the vts timeline and convert to tsusing the latest offset when retrieving the gaze for each video frame):

class VideoFramesAndMappedGaze:

    def __init__(self, gazedata, videoCapture, fps):
        self.__cap__ = videoCapture
        if (self.__cap__.isOpened() == False):
            print("Error opening video stream or file")
            raise IOError
        self.__current_frameAndMappedGaze__ = None
        self.__df__ = gazedata.toDataFrame()
        self.__vts__ = gazedata.getVTS()
        self.__vts_list__ = self.__vts__.values()
        self.__ts_list__ = self.__vts__.keys()
        self.__frame_duration__ = int(1000/fps)
        self.__current_time__ = self.__vts_list__[0]
        self.__i__ = 0
        self.__offset__ = self.__ts_list__[0] - self.__vts_list__[0]

    def __iter__(self):
        return self

    def __next__(self):
        if (self.__cap__.isOpened()):
            ret, frame = self.__cap__.read()
            if ret == True:
                if self.__current_time__ > self.__vts_list__[self.__i__]:
                    if self.__i__ < len(self.__vts_list__) - 1:
                        self.__i__ += 1
                        self.__offset__ = self.__ts_list__[self.__i__] \
                                 - self.__vts_list__[self.__i__]
                T = self.__df__.index[self.__df__.index.get_loc(self.__current_time__\
                    + self.__offset__, method='nearest')]
                x = self.__df__.at[T, GazeData.GazePixelX]
                y = self.__df__.at[T, GazeData.GazePixelY]
            else:
                raise StopIteration
            self.__current_time__ += self.__frame_duration__
            return (frame, x, y, T)
        else:
            raise StopIteration