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

Function draw_stop_signs

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

Source from the content-addressed store, hash-verified

137
138
139def draw_stop_signs(image, vehicle, lights, pixels_per_meter=5.5, size=512, radius=5):
140 image = Image.fromarray(image)
141 draw = ImageDraw.Draw(image)
142
143 transform = vehicle.get_transform()
144 pos = transform.location
145 theta = np.radians(90 + transform.rotation.yaw)
146 R = np.array([
147 [np.cos(theta), -np.sin(theta)],
148 [np.sin(theta), np.cos(theta)],
149 ])
150
151 for light in lights:
152 delta = light.get_transform().location - pos
153
154 target = R.T.dot([delta.x, delta.y])
155 target *= pixels_per_meter
156 target += size // 2
157
158 if min(target) < 0 or max(target) >= size:
159 continue
160
161 trigger = light.trigger_volume
162 light.get_transform().transform(trigger.location)
163 dist = trigger.location.distance(vehicle.get_location())
164 a = np.sqrt(
165 trigger.extent.x ** 2 +
166 trigger.extent.y ** 2 +
167 trigger.extent.z ** 2)
168 b = np.sqrt(
169 vehicle.bounding_box.extent.x ** 2 +
170 vehicle.bounding_box.extent.y ** 2 +
171 vehicle.bounding_box.extent.z ** 2)
172
173 if dist > a + b:
174 continue
175
176 x, y = target
177 draw.ellipse((x-radius, y-radius, x+radius, y+radius), 26)
178
179 return np.array(image)

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