Пример #1
0
 def load_video(self, make_video=False):
     """ loads and returns the video """
     # load video and make it grey scale
     self.video = VideoFile(self.video_file)
     self.video = FilterMonochrome(self.video)
     
     if self.params['input/zoom_factor'] != 1:
         self.video = FilterResize(self.video,
                                   self.params['input/zoom_factor'],
                                   even_dimensions=True)
     
     # restrict video to requested frames
     if self.params['input/frames']:
         frames = self.params['input/frames']
         self.video = self.video[frames[0]: frames[1]]
         
     
     # setup debug output 
     zoom_factor = self.params['output/zoom_factor']
     if make_video:
         if self.output_video is None:
             raise ValueError('Video output filename is not set.')
         self.output = VideoComposer(self.output_video, size=self.video.size,
                                     fps=self.video.fps, is_color=True,
                                     zoom_factor=zoom_factor)
         if self.params['output/show_video']:
             self.debug_window = ImageWindow(self.output.shape,
                                             title=self.video_file,
                                             multiprocessing=False)
         else:
             self.debug_window = None
             
     else:
         self.output = None
Пример #2
0
    def debug_setup(self):
        """ prepares everything for the debug output """
        # load parameters for video output
        video_output_period = int(self.params['output/video/period'])
        video_extension = self.params['output/video/extension']
        video_codec = self.params['output/video/codec']
        video_bitrate = self.params['output/video/bitrate']

        # set up the general video output, if requested
        if 'video' in self.debug_output or 'video.show' in self.debug_output:
            # initialize the writer for the debug video
            debug_file = self.get_filename('pass3' + video_extension, 'debug')
            self.debug['video'] = VideoComposer(
                debug_file,
                size=self.video.size,
                fps=self.video.fps,
                is_color=True,
                output_period=video_output_period,
                codec=video_codec,
                bitrate=video_bitrate)

            if 'video.show' in self.debug_output:
                name = self.name if self.name else ''
                position = self.params['debug/window_position']
                image_window = ImageWindow(
                    self.debug['video'].shape,
                    title='Debug video pass 3 [%s]' % name,
                    multiprocessing=self.params['debug/use_multiprocessing'],
                    position=position)
                self.debug['video.show'] = image_window
Пример #3
0
    def produce_video(self):
        """ prepares everything for the debug output """
        # load parameters for video output        
        video_extension = self.params['output/video/extension']
        video_codec = self.params['output/video/codec']
        video_bitrate = self.params['output/video/bitrate']
        
        if self.video is None:
            self.load_video()
        
        filename = self.get_filename('video' + video_extension, 'video')
        video = VideoComposer(filename, size=self.video.size,
                              fps=self.video.fps, is_color=True,
                              output_period=self.params['output/output_period'],
                              codec=video_codec, bitrate=video_bitrate)
        
        mouse_track = self.data['pass2/mouse_trajectory']
        ground_profile = self.data['pass2/ground_profile']
        
        self.logger.info('Pass 2 - Start producing final video with %d frames', len(self.video))
        
        # we used the first frame to determine the cage dimensions in the first pass
        source_video = self.video[1:]
        
        track_first = 0
        tracks = self.data['pass1/objects/tracks']
        tracks.sort(key=lambda track: track.start)
        burrow_tracks = self.data['pass1/burrows/tracks']
        
        for frame_id, frame in enumerate(display_progress(source_video)):
            # set real video as background
            video.set_frame(frame)
        
            # plot the ground profile
            ground_line = ground_profile.get_groundline(frame_id)
            video.add_line(ground_line, is_closed=False,
                              mark_points=False, color='y')

            # indicate burrow centerline
            for burrow in burrow_tracks.find_burrows(frame_id):
                ground = GroundProfile(ground_line)
                video.add_line(burrow.get_centerline(ground),
                                  'k', is_closed=False, width=2)
        
            # indicate all moving objects
            # find the first track which is still active
            while tracks[track_first].end < frame_id:
                track_first += 1
            # draw all tracks that are still active
            for track in tracks[track_first:]:
                if track.start > frame_id:
                    # this is the last track that can possibly be active
                    break
                elif track.start <= frame_id <= track.end:
                    video.add_circle(track.get_pos(frame_id),
                                     self.params['mouse/model_radius'],
                                     '0.5', thickness=1)

            # indicate the mouse position
            if np.all(np.isfinite(mouse_track.pos[frame_id])):
                video.add_circle(mouse_track.pos[frame_id],
                                 self.params['mouse/model_radius'],
                                 'w', thickness=2)
                    
            
#                 # add additional debug information
            
            video.add_text(str(frame_id), (20, 20), anchor='top')   
#                 video.add_text(str(self.frame_id/self.fps), (20, 20), anchor='top')   
                
        video.close()