MCPcopy Index your code
hub / github.com/OpenDriveLab/DriveAdapter / draw_traffic_lights

Function draw_traffic_lights

leaderboard/team_code/map_agent.py:96–136  ·  view source on GitHub ↗
(image, vehicle, lights, pixels_per_meter=5.5, size=512, radius=5)

Source from the content-addressed store, hash-verified

94
95
96def draw_traffic_lights(image, vehicle, lights, pixels_per_meter=5.5, size=512, radius=5):
97 image = Image.fromarray(image)
98 draw = ImageDraw.Draw(image)
99
100 transform = vehicle.get_transform()
101 pos = transform.location
102 theta = np.radians(90 + transform.rotation.yaw)
103 R = np.array([
104 [np.cos(theta), -np.sin(theta)],
105 [np.sin(theta), np.cos(theta)],
106 ])
107
108 for light in lights:
109 delta = light.get_transform().location - pos
110
111 target = R.T.dot([delta.x, delta.y])
112 target *= pixels_per_meter
113 target += size // 2
114
115 if min(target) < 0 or max(target) >= size:
116 continue
117
118 trigger = light.trigger_volume
119 light.get_transform().transform(trigger.location)
120 dist = trigger.location.distance(vehicle.get_location())
121 a = np.sqrt(
122 trigger.extent.x ** 2 +
123 trigger.extent.y ** 2 +
124 trigger.extent.z ** 2)
125 b = np.sqrt(
126 vehicle.bounding_box.extent.x ** 2 +
127 vehicle.bounding_box.extent.y ** 2 +
128 vehicle.bounding_box.extent.z ** 2)
129
130 if dist > a + b:
131 continue
132
133 x, y = target
134 draw.ellipse((x-radius, y-radius, x+radius, y+radius), 23 + light.state.real) # 13 changed to 23 for carla 0.9.10
135
136 return np.array(image)
137
138
139def draw_stop_signs(image, vehicle, lights, pixels_per_meter=5.5, size=512, radius=5):

Callers 1

tickMethod · 0.85

Calls 4

get_transformMethod · 0.80
dotMethod · 0.80
distanceMethod · 0.80
get_locationMethod · 0.80

Tested by

no test coverage detected