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()