本文整理匯總了Python中carla.Color方法的典型用法代碼示例。如果您正苦於以下問題:Python carla.Color方法的具體用法?Python carla.Color怎麽用?Python carla.Color使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類carla
的用法示例。
在下文中一共展示了carla.Color方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: draw_radar_measurement
# 需要導入模塊: import carla [as 別名]
# 或者: from carla import Color [as 別名]
def draw_radar_measurement(debug_helper: carla.DebugHelper, data: carla.RadarMeasurement, velocity_range=7.5,
size=0.075, life_time=0.06):
"""Code adapted from carla/PythonAPI/examples/manual_control.py:
- White: means static points.
- Red: indicates points moving towards the object.
- Blue: denoted points moving away.
"""
radar_rotation = data.transform.rotation
for detection in data:
azimuth = math.degrees(detection.azimuth) + radar_rotation.yaw
altitude = math.degrees(detection.altitude) + radar_rotation.pitch
# move to local coordinates:
forward_vec = carla.Vector3D(x=detection.depth - 0.25)
global_to_local(forward_vec,
reference=carla.Rotation(pitch=altitude, yaw=azimuth, roll=radar_rotation.roll))
# draw:
debug_helper.draw_point(data.transform.location + forward_vec, size=size, life_time=life_time,
persistent_lines=False, color=carla.Color(255, 255, 255))
# -------------------------------------------------------------------------------------------------
# -- Math
# -------------------------------------------------------------------------------------------------
示例2: draw
# 需要導入模塊: import carla [as 別名]
# 或者: from carla import Color [as 別名]
def draw(self):
actor_z = self.actor.get_location().z
for i in range(self.path_index + 1, len(self.path)):
hop1 = self.path[i - 1][0].transform.location
hop2 = self.path[i][0].transform.location
hop1.z = actor_z
hop2.z = actor_z
if i == len(self.path) - 1:
self.world.debug.draw_arrow(
hop1,
hop2,
life_time=0.5,
color=carla.Color(0, 255, 0),
thickness=0.5)
else:
self.world.debug.draw_line(
hop1,
hop2,
life_time=0.5,
color=carla.Color(0, 255, 0),
thickness=0.5)
示例3: _draw_trigger_volume
# 需要導入模塊: import carla [as 別名]
# 或者: from carla import Color [as 別名]
def _draw_trigger_volume(self, world, tl_actor):
transform = tl_actor.get_transform()
tv = transform.transform(tl_actor.trigger_volume.location)
bbox = carla.BoundingBox(tv, tl_actor.trigger_volume.extent)
tl_state = tl_actor.get_state()
if tl_state in TL_STATE_TO_PIXEL_COLOR:
r, g, b = TL_STATE_TO_PIXEL_COLOR[tl_state]
bbox_color = carla.Color(r, g, b)
else:
bbox_color = carla.Color(0, 0, 0)
bbox_life_time = (1 / self._flags.carla_fps + TL_BBOX_LIFETIME_BUFFER)
world.debug.draw_box(bbox,
transform.rotation,
thickness=0.5,
color=bbox_color,
life_time=bbox_life_time)
示例4: _draw_path
# 需要導入模塊: import carla [as 別名]
# 或者: from carla import Color [as 別名]
def _draw_path(self, life_time=60.0, skip=0):
"""
Draw a connected path from start of route to end.
Green node = start
Red node = point along path
Blue node = destination
"""
for i in range(0, len(self.route_waypoints)-1, skip+1):
w0 = self.route_waypoints[i][0]
w1 = self.route_waypoints[i+1][0]
self.world.debug.draw_line(
w0.transform.location + carla.Location(z=0.25),
w1.transform.location + carla.Location(z=0.25),
thickness=0.1, color=carla.Color(255, 0, 0),
life_time=life_time, persistent_lines=False)
self.world.debug.draw_point(
w0.transform.location + carla.Location(z=0.25), 0.1,
carla.Color(0, 255, 0) if i == 0 else carla.Color(255, 0, 0),
life_time, False)
self.world.debug.draw_point(
self.route_waypoints[-1][0].transform.location + carla.Location(z=0.25), 0.1,
carla.Color(0, 0, 255),
life_time, False)
示例5: plot_trajs_carla
# 需要導入模塊: import carla [as 別名]
# 或者: from carla import Color [as 別名]
def plot_trajs_carla(world, trajs, carla_color, z, line_time=30.0,
show_person_id=False):
for person_id, traj in trajs:
points = zip(traj[:-1], traj[1:])
for p1, p2 in points:
p1 = carla.Location(x=p1[0], y=p1[1], z=z)
p2 = carla.Location(x=p2[0], y=p2[1], z=z)
world.debug.draw_arrow(
p1, p2,
thickness=0.1,
arrow_size=0.1, color=carla_color, life_time=line_time)
if show_person_id:
world.debug.draw_string(
carla.Location(x=traj[0][0], y=traj[0][1], z=z), "# %s" % person_id,
draw_shadow=False, color=carla.Color(r=255, g=0, b=0),
life_time=line_time, persistent_lines=False)
# computed using compute_actev_world_norm.py
# min -> max
示例6: _draw_waypoints
# 需要導入模塊: import carla [as 別名]
# 或者: from carla import Color [as 別名]
def _draw_waypoints(self, world, waypoints, vertical_shift, persistency=-1):
"""
Draw a list of waypoints at a certain height given in vertical_shift.
"""
for w in waypoints:
wp = w[0].location + carla.Location(z=vertical_shift)
size = 0.2
if w[1] == RoadOption.LEFT: # Yellow
color = carla.Color(255, 255, 0)
elif w[1] == RoadOption.RIGHT: # Cyan
color = carla.Color(0, 255, 255)
elif w[1] == RoadOption.CHANGELANELEFT: # Orange
color = carla.Color(255, 64, 0)
elif w[1] == RoadOption.CHANGELANERIGHT: # Dark Cyan
color = carla.Color(0, 64, 255)
elif w[1] == RoadOption.STRAIGHT: # Gray
color = carla.Color(128, 128, 128)
else: # LANEFOLLOW
color = carla.Color(0, 255, 0) # Green
size = 0.1
world.debug.draw_point(wp, size=size, color=color, life_time=persistency)
world.debug.draw_point(waypoints[0][0].location + carla.Location(z=vertical_shift), size=0.2,
color=carla.Color(0, 0, 255), life_time=persistency)
world.debug.draw_point(waypoints[-1][0].location + carla.Location(z=vertical_shift), size=0.2,
color=carla.Color(255, 0, 0), life_time=persistency)
示例7: draw_shortest_path
# 需要導入模塊: import carla [as 別名]
# 或者: from carla import Color [as 別名]
def draw_shortest_path(world, planner, origin, destination):
"""Draws shortest feasible lines/arrows from origin to destination
Args:
world:
planner:
origin (tuple): (x, y, z)
destination (tuple): (x, y, z)
Returns:
next waypoint as a list of coordinates (x,y,z)
"""
hops = get_shortest_path_waypoints(world, planner, origin, destination)
for i in range(1, len(hops)):
hop1 = hops[i - 1][0].transform.location
hop2 = hops[i][0].transform.location
hop1.z = origin[2]
hop2.z = origin[2]
if i == len(hops) - 1:
world.debug.draw_arrow(
hop1,
hop2,
life_time=1.0,
color=carla.Color(0, 255, 0),
thickness=0.5)
else:
world.debug.draw_line(
hop1,
hop2,
life_time=1.0,
color=carla.Color(0, 255, 0),
thickness=0.5)
示例8: draw_shortest_path_old
# 需要導入模塊: import carla [as 別名]
# 或者: from carla import Color [as 別名]
def draw_shortest_path_old(world, planner, origin, destination):
"""Draws shortest feasible lines/arrows from origin to destination
Args:
world:
planner:
origin (typle): (x, y, z)
destination:
Returns:
"""
xys = get_shortest_path_waypoints(planner, (origin[0], origin[1]),
destination)
if len(xys) > 2:
for i in range(len(xys) - 2):
world.debug.draw_line(
carla.Location(*xys[i]),
carla.Location(*xys[i + 1]),
life_time=1.0,
color=carla.Color(0, 255, 0))
elif len(xys) == 2:
world.debug.draw_arrow(
carla.Location(*xys[-2]),
carla.Location(*xys[-1]),
life_time=100.0,
color=carla.Color(0, 255, 0),
thickness=0.5)
示例9: _visualize_imu
# 需要導入模塊: import carla [as 別名]
# 或者: from carla import Color [as 別名]
def _visualize_imu(self, msg):
import carla
transform = msg.transform
# Acceleration measured in ego frame, not global
# z acceleration not useful for visualization so set to 0
rotation_transform = carla.Transform(
location=carla.Location(0, 0, 0),
rotation=transform.rotation.as_carla_rotation())
acceleration = msg.acceleration.as_carla_vector()
rotated_acceleration = rotation_transform.transform(
carla.Location(acceleration.x, acceleration.y, 0))
# Construct arrow.
loc = transform.location.as_carla_location()
begin_acc = loc + carla.Location(z=0.5)
end_acc = begin_acc + carla.Location(rotated_acceleration.x,
rotated_acceleration.y,
0) # not useful for visualization
# draw arrow
self._logger.debug("Acc: {}".format(rotated_acceleration))
self._world.debug.draw_arrow(begin_acc,
end_acc,
arrow_size=0.1,
life_time=0.1,
color=carla.Color(255, 0, 0))
示例10: draw_on_world
# 需要導入模塊: import carla [as 別名]
# 或者: from carla import Color [as 別名]
def draw_on_world(self, world):
import carla
for marking in self.left_markings:
world.debug.draw_point(marking.as_carla_location(),
size=0.1,
color=carla.Color(255, 255, 0))
for marking in self.right_markings:
world.debug.draw_point(marking.as_carla_location(),
size=0.1,
color=carla.Color(255, 255, 0))
示例11: on_marker
# 需要導入模塊: import carla [as 別名]
# 或者: from carla import Color [as 別名]
def on_marker(self, marker_array):
"""
Receive markers from ROS and apply in CARLA
"""
for marker in marker_array.markers:
if marker.header.frame_id != "map":
rospy.logwarn(
"Could not draw marker in frame '{}'. Only 'map' supported.".format(
marker.header.frame_id))
continue
lifetime = -1.
if marker.lifetime:
lifetime = marker.lifetime.to_sec()
color = carla.Color(int(marker.color.r * 255),
int(marker.color.g * 255),
int(marker.color.b * 255),
int(marker.color.a * 255))
if marker.type == Marker.POINTS:
self.draw_points(marker, lifetime, color)
elif marker.type == Marker.LINE_STRIP:
self.draw_line_strips(marker, lifetime, color)
elif marker.type == Marker.ARROW:
self.draw_arrow(marker, lifetime, color)
elif marker.type == Marker.CUBE:
self.draw_box(marker, lifetime, color)
else:
rospy.logwarn("Marker type '{}' not supported.".format(marker.type))
示例12: plot_actor_3d_bbox
# 需要導入模塊: import carla [as 別名]
# 或者: from carla import Color [as 別名]
def plot_actor_3d_bbox(world, actor, color, fps):
color = carla.Color(r=color[0], g=color[1], b=color[2])
# get the current transform (location + rotation)
transform = actor.get_transform()
# bounding box is relative to the actor
bounding_box = actor.bounding_box
bounding_box.location += transform.location # from relative to world
world.debug.draw_box(bounding_box, transform.rotation,
color=color, life_time=1.0/fps)
示例13: plot_actor_3d_bbox
# 需要導入模塊: import carla [as 別名]
# 或者: from carla import Color [as 別名]
def plot_actor_3d_bbox(world, actor, color, fps, thickness=0.1):
color = carla.Color(r=color[0], g=color[1], b=color[2])
# get the current transform (location + rotation)
transform = actor.get_transform()
# bounding box is relative to the actor
bounding_box = actor.bounding_box
bounding_box.location += transform.location # from relative to world
world.debug.draw_box(bounding_box, transform.rotation, thickness=thickness,
color=color, life_time=1.0/fps)
示例14: _build_scenario_instances
# 需要導入模塊: import carla [as 別名]
# 或者: from carla import Color [as 別名]
def _build_scenario_instances(self, world, ego_vehicle, scenario_definitions,
scenarios_per_tick=5, timeout=300, debug_mode=False):
"""
Based on the parsed route and possible scenarios, build all the scenario classes.
"""
scenario_instance_vec = []
if debug_mode:
for scenario in scenario_definitions:
loc = carla.Location(scenario['trigger_position']['x'],
scenario['trigger_position']['y'],
scenario['trigger_position']['z']) + carla.Location(z=2.0)
world.debug.draw_point(loc, size=0.3, color=carla.Color(255, 0, 0), life_time=100000)
world.debug.draw_string(loc, str(scenario['name']), draw_shadow=False,
color=carla.Color(0, 0, 255), life_time=100000, persistent_lines=True)
for scenario_number, definition in enumerate(scenario_definitions):
# Get the class possibilities for this scenario number
scenario_class = NUMBER_CLASS_TRANSLATION[definition['name']]
# Create the other actors that are going to appear
if definition['other_actors'] is not None:
list_of_actor_conf_instances = self._get_actors_instances(definition['other_actors'])
else:
list_of_actor_conf_instances = []
# Create an actor configuration for the ego-vehicle trigger position
egoactor_trigger_position = convert_json_to_transform(definition['trigger_position'])
scenario_configuration = ScenarioConfiguration()
scenario_configuration.other_actors = list_of_actor_conf_instances
scenario_configuration.trigger_points = [egoactor_trigger_position]
scenario_configuration.subtype = definition['scenario_type']
scenario_configuration.ego_vehicles = [ActorConfigurationData('vehicle.lincoln.mkz2017',
ego_vehicle.get_transform(),
'hero')]
route_var_name = "ScenarioRouteNumber{}".format(scenario_number)
scenario_configuration.route_var_name = route_var_name
try:
scenario_instance = scenario_class(world, [ego_vehicle], scenario_configuration,
criteria_enable=False, timeout=timeout)
# Do a tick every once in a while to avoid spawning everything at the same time
if scenario_number % scenarios_per_tick == 0:
if CarlaDataProvider.is_sync_mode():
world.tick()
else:
world.wait_for_tick()
scenario_number += 1
except Exception as e: # pylint: disable=broad-except
if debug_mode:
traceback.print_exc()
print("Skipping scenario '{}' due to setup error: {}".format(definition['name'], e))
continue
scenario_instance_vec.append(scenario_instance)
return scenario_instance_vec
示例15: plot_trajs_carla
# 需要導入模塊: import carla [as 別名]
# 或者: from carla import Color [as 別名]
def plot_trajs_carla(world, traj_data, args, is_vehicle=False):
vehicle_traj_color = ((0, 255, 255), (255, 0, 255))
person_traj_color = ((255, 255, 0), (0, 255, 0))
color = person_traj_color
if is_vehicle:
color = vehicle_traj_color
red = carla.Color(r=255, g=0, b=0)
for pid in traj_data:
trajs = traj_data[pid]
# show the person id at the beginning
string = "Person #%s" % pid
if is_vehicle:
string = "Vehicle #%s" % pid
world.debug.draw_string(
xyz_to_carla(trajs[0]["xyz"]), string,
draw_shadow=False, color=red,
life_time=1.0/args.video_fps)
# just a point:
if len(trajs) == 1:
frame_id = trajs[0]["frame_id"]
# color for observation
this_color = color[0]
if frame_id >= args.moment_frame_ids[args.obs_length]:
# color for prediction period
this_color = color[1]
this_color = carla.Color(
r=this_color[0], g=this_color[1], b=this_color[2])
world.debug.draw_point(
xyz_to_carla(trajs[0]["xyz"]),
color=this_color, size=0.1, life_time=1.0/args.video_fps)
# assuming the trajectory is sorted in time
for p1, p2 in zip(trajs[:-1], trajs[1:]):
frame_id = p2["frame_id"]
# color for observation
this_color = color[0]
if frame_id >= args.moment_frame_ids[args.obs_length]:
# color for prediction period
this_color = color[1]
this_color = carla.Color(
r=this_color[0], g=this_color[1], b=this_color[2])
p1_xyz = xyz_to_carla(p1["xyz"])
p2_xyz = xyz_to_carla(p2["xyz"])
world.debug.draw_arrow(
p1_xyz, p2_xyz,
thickness=0.1,
arrow_size=0.1, color=this_color, life_time=1.0/args.video_fps)
if p2["is_stationary"]:
world.debug.draw_point(
p2_xyz, color=red, size=0.1, life_time=1.0/args.video_fps)