def handle_frame(next):
        if next != cap.get_frame_index():
            #we need to seek:
            #logger.debug("Seeking to Frame %s" %next)
            try:
                cap.seek_to_frame(next)
            except FileSeekError:
                #could not seek to requested position
                #logger.warning("Could not evaluate frame: %s."%next)
                visited_list[next] = True # this frame is now visited.
                q.put((next,[])) # we cannot look at the frame, report no detection
                return
            #seeking invalidates prev markers for the detector
            markers[:] = []

        try:
            frame = cap.get_frame_nowait()
        except EndofVideoFileError:
            #logger.debug("Video File's last frame(s) not accesible")
             #could not read frame
            #logger.warning("Could not evaluate frame: %s."%next)
            visited_list[next] = True # this frame is now visited.
            q.put((next,[])) # we cannot look at the frame, report no detection
            return

        markers[:] = detect_screens(frame.gray)

        visited_list[frame.index] = True
        q.put((frame.index,markers[:])) #object passed will only be pickeled when collected from other process! need to make a copy ot avoid overwrite!!!
Example #2
0
    def recent_events(self,events):
        if 'frame' in events:
            frame = events['frame']
            self.img_shape = frame.height,frame.width,3

            if self.running:
                gray = frame.gray

                # hack "self.markers" instead "self.screens" is keeped for inheritence compatibility
                self.markers = detect_screens(gray)

                if self.mode == "Show marker IDs":
                    draw_markers(frame.img,self.markers)
                    events['frame'] = frame

            # locate surfaces, map gaze
            for s in self.surfaces:
                s.locate(self.markers,self.camera_calibration,self.min_marker_perimeter,self.min_id_confidence, self.locate_3d)
                if s.detected:
                    s.gaze_on_srf = s.map_data_to_surface(events.get('gaze_positions',[]),s.m_from_screen)
                else:
                    s.gaze_on_srf =[]

            events['surface'] = []
            for s in self.surfaces:
                if s.detected:
                    events['surface'].append({
                        'name':s.name,
                        'uid':s.uid,
                        'm_to_screen':s.m_to_screen.tolist(),
                        'm_from_screen':s.m_from_screen.tolist(),
                        'gaze_on_srf': s.gaze_on_srf,
                        'timestamp':frame.timestamp,
                        'camera_pose_3d':s.camera_pose_3d.tolist() if s.camera_pose_3d is not None else None
                    })

            if self.running:
                self.button.status_text = '{}/{}'.format(len([s for s in self.surfaces if s.detected]), len(self.surfaces))
            else:
                self.button.status_text = 'tracking paused'

            if self.mode == 'Show Markers and Surfaces':
                # edit surfaces by user
                if self.edit_surf_verts:
                    window = glfwGetCurrentContext()
                    pos = glfwGetCursorPos(window)
                    pos = normalize(pos,glfwGetWindowSize(window),flip_y=True)
                    for s,v_idx in self.edit_surf_verts:
                        if s.detected:
                            new_pos = s.img_to_ref_surface(np.array(pos))
                            s.move_vertex(v_idx,new_pos)
    def update(self,frame,events):
        self.img_shape = frame.height,frame.width,3

        if self.running:
            gray = frame.gray

            # hack "self.markers" instead "self.screens" is keeped for inheritence compatibility
            self.markers = detect_screens(gray)

            if self.mode == "Show marker IDs":
                draw_markers(frame.img,self.markers)

        events['surfaces'] = []

        # locate surfaces
        for s in self.surfaces:
            s.locate(self.markers,self.camera_calibration,self.min_marker_perimeter, self.locate_3d)
            if s.detected:
                events['surfaces'].append({'name':s.name,'uid':s.uid,'m_to_screen':s.m_to_screen,'m_from_screen':s.m_from_screen, 'timestamp':frame.timestamp})

        if self.running:
            self.button.status_text = '%s/%s'%(len([s for s in self.surfaces if s.detected]),len(self.surfaces))
        else:
            self.button.status_text = 'tracking paused'

        if self.mode == 'Show Markers and Surfaces':
            # edit surfaces by user
            if self.edit_surf_verts:
                window = glfwGetCurrentContext()
                pos = glfwGetCursorPos(window)
                pos = normalize(pos,glfwGetWindowSize(window),flip_y=True)
                for s,v_idx in self.edit_surf_verts:
                    if s.detected:
                        new_pos = s.img_to_ref_surface(np.array(pos))
                        s.move_vertex(v_idx,new_pos)

        #map recent gaze onto detected surfaces used for pupil server
        for s in self.surfaces:
            if s.detected:
                s.gaze_on_srf = []
                for p in events.get('gaze_positions',[]):
                    gp_on_s = tuple(s.img_to_ref_surface(np.array(p['norm_pos'])))
                    p['realtime gaze on ' + s.name] = gp_on_s
                    s.gaze_on_srf.append(gp_on_s)
Example #4
0
        def handle_frame(next_frame):
            if next_frame != cap.get_frame_index():
                #we need to seek:
                #logger.debug("Seeking to Frame %s" %next_frame)
                try:
                    cap.seek_to_frame(next_frame)
                except FileSeekError:
                    put_in_cache(
                        next_frame,
                        [])  # we cannot look at the frame, report no detection
                    return
                #seeking invalidates prev markers for the detector
                # markers[:] = []

            try:
                frame = cap.get_frame()
            except EndofVideoError:
                put_in_cache(
                    next_frame,
                    [])  # we cannot look at the frame, report no detection
                return

            put_in_cache(frame.index, detect_screens(frame.gray))