Ejemplo n.º 1
0
def draw_agent(
    image: np.ndarray,
    agent_center_coord: Tuple[int, int],
    agent_rotation: float,
    agent_radius_px: int = 5,
) -> np.ndarray:
    r"""Return an image with the agent image composited onto it.
    Args:
        image: the image onto which to put the agent.
        agent_center_coord: the image coordinates where to paste the agent.
        agent_rotation: the agent's current rotation in radians.
        agent_radius_px: 1/2 number of pixels the agent will be resized to.
    Returns:
        The modified background image. This operation is in place.
    """

    # Rotate before resize to keep good resolution.
    rotated_agent = scipy.ndimage.interpolation.rotate(
        AGENT_SPRITE, agent_rotation * 180 / np.pi)
    # Rescale because rotation may result in larger image than original, but
    # the agent sprite size should stay the same.
    initial_agent_size = AGENT_SPRITE.shape[0]
    new_size = rotated_agent.shape[0]
    agent_size_px = max(
        1, int(agent_radius_px * 2 * new_size / initial_agent_size))
    resized_agent = cv2.resize(
        rotated_agent,
        (agent_size_px, agent_size_px),
        interpolation=cv2.INTER_LINEAR,
    )
    utils.paste_overlapping_image(image, resized_agent, agent_center_coord)
    return image
Ejemplo n.º 2
0
    max_weight_i = np.argmax(loc[aux_tasks])
    color = colors[max_weight_i]
    p_x, p_y = maps.to_grid(
        loc['pos_x'],
        loc['pos_y'],
        COORDINATE_MIN,
        COORDINATE_MAX,
        map_resolution,
    )
    a_x = p_x - CLIPPED_X
    a_y = p_y - CLIPPED_Y
    box = (np.ones((*box_size, 3)) * 255 * color).astype(np.uint8)
    utils.paste_overlapping_image(
        background=top_down_map,
        foreground=box,
        location=(a_x, a_y)
    )

a, b = 4, 4
n = 9
r = 3

y,x = np.ogrid[-a:n-a, -b:n-b]
mask = x*x + y*y <= r*r
goal_circle = np.zeros((n, n, 3))
goal_circle[mask] = 255
goal_center = maps.to_grid(
    goal[0], goal[2], COORDINATE_MIN, COORDINATE_MAX, map_resolution
)
goal_a_x, goal_a_y = goal_center[0] - CLIPPED_X, goal_center[1] - CLIPPED_Y