Exemplo n.º 1
0
    def exportVideoAndGaze(self, filepath=None, filename='output.avi', segment_id=1, aoi_models=[]):
        logging.info('Exporting video with mapped gaze in file %s in folder %s' % (filename, filepath))
        data = self.getGazeData(segment_id)
        fps = data.getFrameFPS()
        width = data.getFrameWidth()
        height = data.getFrameHeight()
        f = self.__recording__.getSegment(segment_id).getVideoFilename()
        cap = cv2.VideoCapture(f)
        framesAndGaze = iter(VideoFramesAndMappedGaze(data, cap, fps))
        fourcc = cv2.VideoWriter_fourcc(*'XVID')
        out = cv2.VideoWriter(filename,fourcc, fps, (width,height))
        for frame, x, y, ts in framesAndGaze:
            for model in aoi_models:
                model.apply(frame, ts, x, y)
                model.drawAOIsBox(frame, ts)

            if x>0 and y>0:
                color = (0,0,255)
                aoi_id = model.getAOI(ts, x, y)
                if not aoi_id is None:
                    color = (0,255,0)
                    cv2.putText(frame, aoi_id, (x, y), cv2.FONT_HERSHEY_SIMPLEX, 0.7, (0, 255, 0), 2)
                cv2.circle(frame,(x,y), 30, color , 2)
            out.write(frame)
        cap.release()
        model.exportHeatmap()
Exemplo n.º 2
0
 def saveVideoSnapshot(self, filename, ts, segment_id):
     logging.info('Saving snapshot from video recording in %s ' % filename)
     segment = self.__recording__.getSegment(segment_id)
     fps = segment.getFrameFPS()
     f = segment.getVideoFilename()
     cap = cv2.VideoCapture(f)
     framesAndGaze = iter(VideoFramesAndMappedGaze(data, cap, fps))
     for frame, x, y, _ts in framesAndGaze:
         if _ts > ts:
             cv2.imwrite(filename,frame)
             break
     cap.release()
Exemplo n.º 3
0
    def exportFull(self, fixation_filter, filepath='.', csv_filename='output.csv', video_filename='output.avi', segment_id=1, aoi_models=[], ts_filter=None):
        fixations = self.getFixations(fixation_filter, ts_filter=ts_filter, segment_id=segment_id)
        logging.info('Exporting video with mapped fixations in folder %s' % filepath)
        data = self.getGazeData(segment_id)
        fps = data.getFrameFPS()
        width = data.getFrameWidth()
        height = data.getFrameHeight()
        f = self.__recording__.getSegment(segment_id).getVideoFilename()
        cap = cv2.VideoCapture(f)
        framesAndGaze = iter(VideoFramesAndMappedGaze(data, cap, fps))
        fourcc = cv2.VideoWriter_fourcc(*'XVID')
        out = cv2.VideoWriter(os.path.join(filepath, video_filename),fourcc, fps, (width,height))


        for frame, x, y, ts in framesAndGaze:
            if not (x > 0 or y > 0):
                continue
            gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
            #aruco_dict = aruco.Dictionary_get(aruco.DICT_4X4_100)
            #parameters =  aruco.DetectorParameters_create()
            #corners, ids, rejectedImgPoints = aruco.detectMarkers(gray, aruco_dict, parameters=parameters)
            (fx, fy, duration) = fixations.getClosestFixation(ts)

            for model in aoi_models:
                model.apply(frame, ts, fx, fy, fixations)

            if fx>0 and fy>0:
                color = (0,0,255)
                for model in aoi_models:
                    aoi_id = model.getAOI(ts, fx, fy)
                    if not aoi_id is None:
                        color = (0,255,0)
                    model.drawAOIsBox(frame, ts)
                cv2.circle(frame,(fx,fy), 60, color , 2)
            #frame_markers = aruco.drawDetectedMarkers(frame.copy(), corners, ids)
            out.write(frame)
        cap.release()

        for model in aoi_models:
            for ts in fixations.getTimestamps():
                (fx, fy, duration) = fixations.getClosestFixation(ts)
                aoi_id = model.getAOI(ts, fx, fy)
                if model.contains(ts, aoi_id, fx, fy):
                    fixations.setAOI(ts, 0, 0, aoi_id, 100)
            model.exportHeatmap(filepath)

        (filepath, filename) = self.__getFileParams__('csv', segment_id, filepath, filename=None, suffix='Fixations')
        fixations.exportCSV(filepath, filename, ts_filter=None)
        #(filepath, filename) = self.__getFileParams__('pickle', segment_id, filepath, filename=None)
        #fixations.to_pickle(filename, ts_filter=ts_filter)
        (filepath, filename) = self.__getFileParams__('csv', segment_id, filepath, filename=None, suffix='Filtered')
        self.exportCSV_Filtered(filepath=filepath, fixation_filter=fixation_filter, ts_filter=ts_filter)
Exemplo n.º 4
0
    def replay(self, segment_id=1, aoi_models=[]):
        logging.info('Replaying video with mapped gaze...')
        data = self.getGazeData(segment_id)
        fps = data.getFrameFPS()
        width = data.getFrameWidth()
        height = data.getFrameHeight()
        f = self.__recording__.getSegment(segment_id).getVideoFilename()
        cap = cv2.VideoCapture(f)
        framesAndGaze = iter(VideoFramesAndMappedGaze(data, cap, fps))

        for frame, x, y, ts in framesAndGaze:
            if x>0 and y>0:
                color = (0,0,255)
                for model in aoi_models:
                    model.apply(frame, ts, x, y)
                    model.drawAOIsBox(frame, ts)

                cv2.circle(frame,(x,y), 60, color , 2)
            cv2.imshow('Frame',frame)
            if cv2.waitKey(25) & 0xFF == ord('q'):
                break
        cap.release()
        cv2.destroyAllWindows()