Пример #1
0
 def parse_traffic_lights(self, traffic_lights):
     # Each entry of traffic lights is a dictionary that contains four
     # items, the id, state, position, and trigger volume of the traffic
     # light.
     # WARNING: Some of the methods in the TrafficLight class may not work
     # here  (e.g. methods that depend knowing the town we are in).
     traffic_lights_list = []
     traffic_light_labels = {
         0: TrafficLightColor.RED,
         1: TrafficLightColor.YELLOW,
         2: TrafficLightColor.GREEN
     }
     for traffic_light_dict in traffic_lights.values():
         traffic_light_id = traffic_light_dict['id']
         traffic_light_state = traffic_light_labels[
             traffic_light_dict['state']]
         # Trigger volume is currently unused.
         # traffic_light_trigger_volume = \
         #    traffic_light_dict['trigger_volume']
         location = pylot.utils.Location.from_gps(
             *traffic_light_dict['position'])
         traffic_lights_list.append(
             TrafficLight(
                 1.0,  # confidence
                 traffic_light_state,
                 traffic_light_id,
                 pylot.utils.Transform(
                     location, pylot.utils.Rotation())  # No rotation given
             ))
     return traffic_lights_list
Пример #2
0
def get_actors(world):
    actor_list = world.get_actors()
    tl_actors = actor_list.filter('traffic.traffic_light*')
    traffic_lights = [
        TrafficLight.from_carla_actor(tl_actor) for tl_actor in tl_actors
    ]
    traffic_stop_actors = actor_list.filter('traffic.stop')
    traffic_stops = [
        StopSign.from_carla_actor(ts_actor) for ts_actor in traffic_stop_actors
    ]
    speed_limit_actors = actor_list.filter('traffic.speed_limit*')
    speed_signs = [
        SpeedLimitSign.from_carla_actor(ts_actor)
        for ts_actor in speed_limit_actors
    ]
    return (tl_actors, traffic_lights, traffic_stops, speed_signs)
Пример #3
0
 def __convert_to_detected_tl(self, boxes, scores, labels, height, width):
     traffic_lights = []
     for index in range(len(scores)):
         if scores[
                 index] > self._flags.traffic_light_det_min_score_threshold:
             bbox = BoundingBox2D(
                 int(boxes[index][1] * width),  # x_min
                 int(boxes[index][3] * width),  # x_max
                 int(boxes[index][0] * height),  # y_min
                 int(boxes[index][2] * height)  # y_max
             )
             traffic_lights.append(
                 TrafficLight(scores[index],
                              labels[index],
                              bounding_box=bbox))
     return traffic_lights
Пример #4
0
def extract_data_in_pylot_format(actor_list):
    """Extracts actor information in pylot format from an actor list.

    Args:
        actor_list (carla.ActorList): An actor list object with all the
            simulation actors.

    Returns:
        A tuple that contains objects for all different types of actors.
    """
    # Note: the output will include the ego vehicle as well.
    vec_actors = actor_list.filter('vehicle.*')
    vehicles = [
        Obstacle.from_simulator_actor(vec_actor) for vec_actor in vec_actors
    ]

    person_actors = actor_list.filter('walker.pedestrian.*')
    people = [
        Obstacle.from_simulator_actor(ped_actor) for ped_actor in person_actors
    ]

    tl_actors = actor_list.filter('traffic.traffic_light*')
    traffic_lights = [
        TrafficLight.from_simulator_actor(tl_actor) for tl_actor in tl_actors
    ]

    speed_limit_actors = actor_list.filter('traffic.speed_limit*')
    speed_limits = [
        SpeedLimitSign.from_simulator_actor(ts_actor)
        for ts_actor in speed_limit_actors
    ]

    traffic_stop_actors = actor_list.filter('traffic.stop')
    traffic_stops = [
        StopSign.from_simulator_actor(ts_actor)
        for ts_actor in traffic_stop_actors
    ]

    return (vehicles, people, traffic_lights, speed_limits, traffic_stops)
Пример #5
0
def log_traffic_lights(world):
    world_map = world.get_map()
    (traffic_lights, _, _, _) = get_actors(world)
    tl_colors = [
        carla.TrafficLightState.Yellow, carla.TrafficLightState.Green,
        carla.TrafficLightState.Red
    ]
    transforms_of_interest = []
    for light in traffic_lights:
        print("Working for traffic light {}".format(light.id))
        # For every traffic light, get the neighbouring lights except the one
        # directly opposite.
        for offset in range(10, 40, 5):
            # Traffic lights have different coordinate systems, hence
            # we need to offset y, instead of x and add that to the trigger
            # volume location.
            offset_loc = pylot.utils.Location(
                x=light.trigger_volume.location.x,
                y=light.trigger_volume.location.y + offset,
                z=light.trigger_volume.location.z)
            offset_trans = pylot.utils.Transform(offset_loc,
                                                 pylot.utils.Rotation())

            # Transform the offset relative to the traffic light.
            transform = pylot.utils.Transform.from_carla_transform(
                light.get_transform()) * offset_trans
            location = transform.location.as_carla_location()

            # Get the waypoint nearest to the transform.
            w = world_map.get_waypoint(location,
                                       project_to_road=True,
                                       lane_type=carla.LaneType.Driving)
            w_rotation = w.transform.rotation
            camera_transform = pylot.utils.Transform.from_carla_transform(
                w.transform)
            camera_transform.location.z += 2.0
            transform = camera_transform.as_carla_transform()
            transforms_of_interest.append(transform)

            # Get the right lanes.
            wp_right = w.get_right_lane()
            while wp_right and wp_right.lane_type == carla.LaneType.Driving \
                    and w_rotation == wp_right.transform.rotation:
                camera_transform = pylot.utils.Transform.from_carla_transform(
                    wp_right.transform)
                camera_transform.location.z += 2.0
                transform = camera_transform.as_carla_transform()
                transforms_of_interest.append(transform)
                wp_right = wp_right.get_right_lane()

            # Get the left lanes.
            wp_left = w.get_left_lane()
            while wp_left and wp_left.lane_type == carla.LaneType.Driving and \
                    w_rotation == wp_left.transform.rotation:
                camera_transform = pylot.utils.Transform.from_carla_transform(
                    wp_left.transform)
                camera_transform.location.z += 2.0
                transform = camera_transform.as_carla_transform()
                transforms_of_interest.append(transform)
                wp_left = wp_left.get_left_lane()

    print("The total number of transforms were: {}".format(
        len(transforms_of_interest)))

    traffic_lights = [
        TrafficLight.from_carla_actor(light) for light in traffic_lights
    ]
    for weather in find_weather_presets():
        change_weather(world, weather)
        time.sleep(1)
        for tl_color in tl_colors:
            change_traffic_light_colors(world, tl_color)
            world.tick()
            time.sleep(1)
            log_obstacles(world, transforms_of_interest, traffic_lights,
                          tl_color, None, None, weather, world_map.name)