Open ajdroid opened 4 years ago
I think one way to solve this would be (keep current time in the vts
timeline and convert to ts
using 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
In
video.py
, theVideoFramesAndMappedGaze
does sync in this way:As I understand it,
current_time
is the current frame'sts
and you are finding the nearestts
in the gaze data. Here, why is thei
counter being added tocurrent_time
?