コード例 #1
0
def show_map_and_traj():
    import matplotlib.pyplot as plt
    from pgdrive.obs.top_down_renderer import draw_top_down_map, draw_top_down_trajectory
    import json
    import cv2
    import pygame
    env = MultiAgentIntersectionEnv()
    env.reset()
    with open("metasvodist_inter_best.json", "r") as f:
        traj = json.load(f)
    m = draw_top_down_map(env.current_map,
                          simple_draw=False,
                          return_surface=True,
                          reverse_color=True)
    m = draw_top_down_trajectory(m,
                                 traj,
                                 entry_differ_color=True,
                                 color_list=[(255, 0, 0), (0, 255, 0),
                                             (0, 0, 255), (255, 255, 0)])
    ret = cv2.resize(pygame.surfarray.pixels_red(m), (512, 512),
                     interpolation=cv2.INTER_LINEAR)
    #
    plt.imshow(ret)
    plt.show()
    pygame.image.save(m, "image.jpg")
    env.close()
コード例 #2
0
def _draw():
    env = MultiAgentIntersectionEnv()
    o = env.reset()
    from pgdrive.utils.draw_top_down_map import draw_top_down_map
    import matplotlib.pyplot as plt

    plt.imshow(draw_top_down_map(env.current_map))
    plt.show()
    env.close()
コード例 #3
0
def test_save_map_image():
    os.makedirs("tmp_images", exist_ok=True)
    setup_logger(debug=True)
    env = PGDriveEnv(dict(environment_num=20, start_seed=0, map=10))
    try:
        for i in range(5):
            env.reset()
            surface = draw_top_down_map(env.current_map, resolution=(128, 128))
            plt.imshow(surface, cmap="Greys")
            plt.savefig("tmp_images/map_{}.png".format(i))
        env.close()
    finally:
        env.close()
コード例 #4
0
def _t(num_blocks):
    default_config = PGDriveEnv.default_config()
    initialize_engine(default_config)
    set_global_random_seed(0)
    try:
        map_config = default_config["map_config"]
        map_config.update(dict(type="block_num", config=num_blocks))
        map = CityMap(map_config, random_seed=map_config["seed"])
        fig = draw_top_down_map(map, (1024, 1024))
        plt.imshow(fig, cmap="bone")
        plt.xticks([])
        plt.yticks([])
        plt.title("Building a City with {} blocks!".format(num_blocks))
        plt.show()
    finally:
        close_engine()
コード例 #5
0
from pgdrive import PGDriveEnv
from pgdrive.component.map.base_map import BaseMap, MapGenerateMethod
from pgdrive.utils.draw_top_down_map import draw_top_down_map

if __name__ == '__main__':
    env = PGDriveEnv(
        dict(environment_num=1,
             map_config={
                 BaseMap.GENERATE_TYPE: MapGenerateMethod.BIG_BLOCK_SEQUENCE,
                 BaseMap.GENERATE_CONFIG: "OCrRCTXRCCCCrOr",
                 BaseMap.LANE_WIDTH: 3.5,
                 BaseMap.LANE_NUM: 3,
             }))
    for i in range(100):
        env.reset()
        map = draw_top_down_map(env.current_map)
        print("Finish {} maps!".format(i + 1))