def _plot_track_on_gradient(self, gradient_img): """ For the given gradient apply the track iconographic image and use this to apply gradient on each camera frame. Previously this was done on the top camera which changed every frame. But with the track iconographic image set static, adding the track on gradient is more optimized. Arguments: gradient_img (str): Gradient image Returns: (Image): Edited gradient image with track image """ track_icongraphy_scaled = utils.resize_image(self.track_icongraphy_img, SCALE_RATIO) track_icongraphy_alpha = track_icongraphy_scaled[:, :, 3] / 255.0 # Track image is placed at the bottom right with some offset (only in leaderboard tracks) x_min = -(self.track_loc_offset[1] + track_icongraphy_scaled.shape[0]) x_max = gradient_img.shape[0] - self.track_loc_offset[1] y_min = -(self.track_loc_offset[0] + track_icongraphy_scaled.shape[1]) y_max = gradient_img.shape[1] - self.track_loc_offset[0] # This is used as the offset for plotting the agent dots self.track_start_loc = (gradient_img.shape[1] + y_min, gradient_img.shape[0] + x_min) for channel in range(0, 4): gradient_img[x_min:x_max, y_min:y_max, channel] =\ (track_icongraphy_alpha * track_icongraphy_scaled[:, :, channel]) + \ (1 - track_icongraphy_alpha) * (gradient_img[x_min:x_max, y_min:y_max, channel]) return gradient_img
def _plot_track_on_gradient(self, gradient_img_path): """ For the given gradient apply the track iconographic image and use this to apply gradient on each camera frame. Previously this was done on the top camera which changed every frame. But with the track iconographic image set static, adding the track on gradient is more optimized. Arguments: gradient_img_path (str): Gradient image path Returns: (Image): Edited gradient image with track image """ gradient_img = utils.get_image( gradient_img_path, IconographicImageSize.FULL_IMAGE_SIZE.value) gradient_img = cv2.cvtColor(gradient_img, cv2.COLOR_RGBA2BGRA) track_icongraphy_scaled = utils.resize_image(self.track_icongraphy_img, SCALE_RATIO) track_icongraphy_alpha = track_icongraphy_scaled[:, :, 3] / 255.0 # Track image is placed at the top left self._track_x_min = self.track_loc_offset[1] self._track_x_max = self.track_loc_offset[ 1] + track_icongraphy_scaled.shape[0] self._track_y_min = self.track_loc_offset[0] self._track_y_max = self.track_loc_offset[ 0] + track_icongraphy_scaled.shape[1] # This is used as the offset for plotting the agent dots self.track_start_loc = (self._track_y_min, self._track_x_min) for channel in range(0, 4): gradient_img[self._track_x_min:self._track_x_max, self._track_y_min:self._track_y_max, channel] =\ (track_icongraphy_alpha * track_icongraphy_scaled[:, :, channel]) + \ (1 - track_icongraphy_alpha) * (gradient_img[self._track_x_min:self._track_x_max, self._track_y_min:self._track_y_max, channel]) return gradient_img