def _update_racers_metrics(self): """ Used to update the racers metric information """ if not rospy.is_shutdown(): video_metrics = self.mp4_video_metrics_srv( VideoMetricsSrvRequest()) self._agents_metrics.put(video_metrics)
def _edit_major_cv_image(self, major_cv_image): """ Apply all the editing for the Major 45degree camera image Args: major_cv_image (Image): Image straight from the camera Returns: Image: Edited main camera image """ # Applying gradient to whole major image and then writing text major_cv_image = utils.apply_gradient(major_cv_image, self.gradient_img, self.gradient_alpha) # Subscribing to the agent metrics mp4_video_metrics_info = list() for racecar_info, mp4_video_metrics_srv in zip( self.racecars_info, self.mp4_video_metrics_srv_list): mp4_video_metrics = mp4_video_metrics_srv(VideoMetricsSrvRequest()) mp4_video_metrics_info.append(mp4_video_metrics) # Adding display name to the image agents_speed = 0 agent_done = False for i, racecar_info in enumerate(self.racecars_info): loc_x, loc_y = XYPixelLoc.MULTI_AGENT_DISPLAY_NAME_LOC.value[i][ 0], XYPixelLoc.MULTI_AGENT_DISPLAY_NAME_LOC.value[i][1] # Display name (Racer name/Model name) display_name = racecar_info['display_name'] display_name_txt = display_name if len( display_name) < 15 else "{}...".format(display_name[:15]) major_cv_image = utils.write_text_on_image( image=major_cv_image, text=display_name_txt, loc=(loc_x, loc_y), font=self.amazon_ember_regular_20px, font_color=RaceCarColorToRGB.White.value, font_shadow_color=RaceCarColorToRGB.Black.value) # Lap Counter loc_y += 30 total_laps = rospy.get_param("NUMBER_OF_TRIALS", 0) current_lap = int(mp4_video_metrics_info[i].lap_counter) + 1 lap_counter_text = "{}/{}".format(current_lap, total_laps) major_cv_image = utils.write_text_on_image( image=major_cv_image, text=lap_counter_text, loc=(loc_x, loc_y), font=self.amazon_ember_heavy_30px, font_color=RaceCarColorToRGB.White.value, font_shadow_color=RaceCarColorToRGB.Black.value) # Reset counter loc_y += 45 reset_counter_text = "Reset | {}".format( mp4_video_metrics_info[i].reset_counter) major_cv_image = utils.write_text_on_image( image=major_cv_image, text=reset_counter_text, loc=(loc_x, loc_y), font=self.amazon_ember_light_18px, font_color=RaceCarColorToRGB.White.value, font_shadow_color=RaceCarColorToRGB.Black.value) if self.racecar_name == racecar_info['name']: agents_speed = mp4_video_metrics_info[i].throttle # The race is complete when total lap is same as current lap and done flag is set agent_done = agent_done or (mp4_video_metrics_info[i].done and (current_lap == int(total_laps))) # Speed loc_x, loc_y = XYPixelLoc.SPEED_EVAL_LOC.value if self.is_league_leaderboard: loc_x, loc_y = XYPixelLoc.SPEED_LEADERBOARD_LOC.value speed_text = "{} m/s".format( utils.get_speed_formatted_str(agents_speed)) major_cv_image = utils.write_text_on_image( image=major_cv_image, text=speed_text, loc=(loc_x, loc_y), font=self.amazon_ember_light_20px, font_color=RaceCarColorToRGB.White.value, font_shadow_color=RaceCarColorToRGB.Black.value) # Leaderboard name if self.is_league_leaderboard: major_cv_image = utils.write_text_on_image( image=major_cv_image, text=self.leaderboard_name, loc=XYPixelLoc.LEADERBOARD_NAME_LOC.value, font=self.amazon_ember_regular_16px, font_color=RaceCarColorToRGB.White.value, font_shadow_color=RaceCarColorToRGB.Black.value) # Evaluation type loc_x, loc_y = XYPixelLoc.RACE_TYPE_EVAL_LOC.value if self.is_league_leaderboard: loc_x, loc_y = XYPixelLoc.RACE_TYPE_RACE_LOC.value race_text = "race" if self.is_racing else "evaluation" evaluation_type_txt = "{} {}".format( RACE_TYPE_TO_VIDEO_TEXT_MAPPING[self.race_type], race_text) major_cv_image = utils.write_text_on_image( image=major_cv_image, text=evaluation_type_txt, loc=(loc_x, loc_y), font=self.amazon_ember_light_italic_20px, font_color=RaceCarColorToRGB.White.value, font_shadow_color=RaceCarColorToRGB.Black.value) # total_evaluation_time (Race time) loc_x, loc_y = XYPixelLoc.MULTI_AGENT_EVAL_TIME.value total_eval_milli_seconds = mp4_video_metrics_info[ 0].total_evaluation_time time_delta = datetime.timedelta(milliseconds=total_eval_milli_seconds) total_eval_time_text = "Race | {}".format( utils.milliseconds_to_timeformat(time_delta)) major_cv_image = utils.write_text_on_image( image=major_cv_image, text=total_eval_time_text, loc=(loc_x, loc_y), font=self.amazon_ember_light_18px, font_color=RaceCarColorToRGB.White.value, font_shadow_color=RaceCarColorToRGB.Black.value) # AWS Deepracer logo at the bottom for the community leaderboard if self.is_league_leaderboard: major_cv_image = utils.write_text_on_image( image=major_cv_image, text=AWS_DEEPRACER_WATER_MARK, loc=XYPixelLoc.AWS_DEEPRACER_WATER_MARK_LOC.value, font=self.amazon_ember_regular_16px, font_color=RaceCarColorToRGB.White.value, font_shadow_color=RaceCarColorToRGB.Black.value) # Check if the done flag is set and set the banner appropriately if agent_done: # When the cv2 text is written, it automatically drops the alpha value of the image rel_y_offset = XYPixelLoc.TRACK_IMG_WITH_OFFSET_LOC.value[ 1] if self.is_league_leaderboard else 0 major_cv_image = cv2.cvtColor(major_cv_image, cv2.COLOR_RGB2RGBA) racecomplete_image = utils.get_image( TrackAssetsIconographicPngs.RACE_COMPLETE_OVERLAY_PNG.value, IconographicImageSize.RACE_COMPLETE_IMAGE_SIZE.value) x_offset = major_cv_image.shape[ 1] - racecomplete_image.shape[1] // 2 y_offset = major_cv_image.shape[ 0] - RACE_COMPLETE_Y_OFFSET - rel_y_offset - racecomplete_image.shape[ 0] // 2 major_cv_image = utils.plot_rectangular_image_on_main_image( major_cv_image, racecomplete_image, (x_offset, y_offset)) return major_cv_image
def _edit_major_cv_image(self, major_cv_image): """ Apply all the editing for the Major 45degree camera image Args: major_cv_image (Image): Image straight from the camera Returns: Image: Edited main camera image """ # Applying gradient to whole major image and then writing text major_cv_image = utils.apply_gradient(major_cv_image, self.gradient_img, self.gradient_alpha) # Subscribing to the agent metrics mp4_video_metrics_info = list() for racecar_info, mp4_video_metrics_srv in zip( self.racecars_info, self.mp4_video_metrics_srv_list): mp4_video_metrics = mp4_video_metrics_srv(VideoMetricsSrvRequest()) mp4_video_metrics_info.append(mp4_video_metrics) # Adding display name to the image display_name_loc = [(10, 10), (450, 10)] agents_speed = 0 agent_done = False for i, racecar_info in enumerate(self.racecars_info): loc_x, loc_y = display_name_loc[i][0], display_name_loc[i][1] # Display name (Racer name/Model name) display_name = racecar_info['display_name'] display_name_txt = display_name if len( display_name) < 15 else "{}...".format(display_name[:15]) major_cv_image = utils.write_text_on_image( image=major_cv_image, text=display_name_txt, loc=(loc_x, loc_y), font=self.amazon_ember_regular_20px, font_color=RaceCarColorToRGB.White.value, font_shadow_color=RaceCarColorToRGB.Black.value) # Lap Counter loc_y += 30 total_laps = rospy.get_param("NUMBER_OF_TRIALS", 0) lap_counter_text = "{}/{}".format( int(mp4_video_metrics_info[i].lap_counter), total_laps) major_cv_image = utils.write_text_on_image( image=major_cv_image, text=lap_counter_text, loc=(loc_x, loc_y), font=self.amazon_ember_heavy_30px, font_color=RaceCarColorToRGB.White.value, font_shadow_color=RaceCarColorToRGB.Black.value) # Reset counter loc_y += 45 reset_counter_text = "Reset | {}".format( mp4_video_metrics_info[i].reset_counter) major_cv_image = utils.write_text_on_image( image=major_cv_image, text=reset_counter_text, loc=(loc_x, loc_y), font=self.amazon_ember_light_18px, font_color=RaceCarColorToRGB.White.value, font_shadow_color=RaceCarColorToRGB.Black.value) if self.racecar_name == racecar_info['name']: agents_speed = mp4_video_metrics_info[i].throttle agent_done = agent_done or mp4_video_metrics_info[i].done # Speed loc_x, loc_y = 10, 420 speed_text = "{} m/s".format( utils.get_speed_formatted_str(agents_speed)) major_cv_image = utils.write_text_on_image( image=major_cv_image, text=speed_text, loc=(loc_x, loc_y), font=self.amazon_ember_light_20px, font_color=RaceCarColorToRGB.White.value, font_shadow_color=RaceCarColorToRGB.Black.value) # Evaluation type loc_y += 25 # TODO - Show text based on whether its a race or customer run evaluation race_text = "race" evaluation_type_txt = "{} {}".format( RACE_TYPE_TO_VIDEO_TEXT_MAPPING[self.race_type], race_text) major_cv_image = utils.write_text_on_image( image=major_cv_image, text=evaluation_type_txt, loc=(loc_x, loc_y), font=self.amazon_ember_light_italic_20px, font_color=RaceCarColorToRGB.White.value, font_shadow_color=RaceCarColorToRGB.Black.value) # total_evaluation_time (Race time) loc_x, loc_y = 240, 10 total_eval_milli_seconds = mp4_video_metrics_info[ 0].total_evaluation_time time_delta = datetime.timedelta(milliseconds=total_eval_milli_seconds) total_eval_time_text = "Race | {}".format( utils.milliseconds_to_timeformat(time_delta)) major_cv_image = utils.write_text_on_image( image=major_cv_image, text=total_eval_time_text, loc=(loc_x, loc_y), font=self.amazon_ember_light_18px, font_color=RaceCarColorToRGB.White.value, font_shadow_color=RaceCarColorToRGB.Black.value) # Check if the done flag is set and set the banner appropriately if agent_done: # When the cv2 text is written, it automatically drops the alpha value of the image major_cv_image = cv2.cvtColor(major_cv_image, cv2.COLOR_RGB2RGBA) racecomplete_image = utils.get_image( TrackAssetsIconographicPngs.RACE_COMPLETE_OVERLAY_PNG.value, IconographicImageSize.RACE_COMPLETE_IMAGE_SIZE.value) x_offset = major_cv_image.shape[ 1] - racecomplete_image.shape[1] // 2 y_offset = major_cv_image.shape[ 0] - 180 - racecomplete_image.shape[0] // 2 major_cv_image = utils.plot_rectangular_image_on_main_image( major_cv_image, racecomplete_image, (x_offset, y_offset)) return major_cv_image