Ejemplo n.º 1
0
 def __init__(self, control_panel):
     self.last_frame_num = 0
     self.prev_frame_analysis = None
     self.ready_frames = Queue.Queue()
     self.tracking_frames = collections.deque()
     self.spots_tracker = SpotsTracker()
     self.control_panel = control_panel
Ejemplo n.º 2
0
class SubtrackerContext:

    def __init__(self, control_panel):
        self.last_frame_num = 0
        self.prev_frame_analysis = None
        self.ready_frames = Queue.Queue()
        self.tracking_frames = collections.deque()
        self.spots_tracker = SpotsTracker()
        self.control_panel = control_panel

    def feed(self, frame, timestamp, playback_time):
        # Create the controls associated to a frame
        frame_controls = self.control_panel.create_frame_controls()

        # Initialize settings
        frame_settings = FrameSettings(frame_controls)

        # Create the FrameAnalysis object
        frame_analysis = FrameAnalysis(frame, self.last_frame_num, timestamp, playback_time, frame_settings, self.prev_frame_analysis, frame_controls)
        self.last_frame_num += 1

        # Do all sort of nice things to the frame
        # TODO
        frame_analysis.do_undistort_frame()
        frame_analysis.do_table_tracking()
        frame_analysis.do_compute_ball_density()
        frame_analysis.find_spots()

        # Pass the frame to the spots tracker
        # TODO
        self.tracking_frames.append(frame_analysis)
        # logger.debug(repr((frame_analysis.frame_num, frame_analysis.timestamp)))
        spots = frame_analysis.spots
        layer = Layer(spots, frame_analysis.frame_num, frame_analysis.timestamp)
        ready_info = self.spots_tracker.push_back_and_get_info(layer)
        for ready_frame_num, ready_position in ready_info:
            ready_frame_analysis = self.tracking_frames.popleft()
            assert ready_frame_analysis.frame_num == ready_frame_num
            ready_frame_analysis.ball_pos = ready_position
            self.ready_frames.put(ready_frame_analysis)

        # Save frame analysis as previous one
        self.prev_frame_analysis = frame_analysis

    def get_processed_frame(self):
        try:
            frame_analysis = self.ready_frames.get(block=False)
            self.ready_frames.task_done()
            return frame_analysis
        except Queue.Empty:
            return None