(weak_self, image)
| 545 | |
| 546 | @staticmethod |
| 547 | def _parse_image(weak_self, image): |
| 548 | self = weak_self() |
| 549 | if not self: |
| 550 | return |
| 551 | if self.sensors[self.index][0].startswith('sensor.lidar'): |
| 552 | points = np.frombuffer(image.raw_data, dtype=np.dtype('f4')) |
| 553 | points = np.reshape(points, (int(points.shape[0] / 3), 3)) |
| 554 | lidar_data = np.array(points[:, :2]) |
| 555 | lidar_data *= min(self.hud.dim) / 100.0 |
| 556 | lidar_data += (0.5 * self.hud.dim[0], 0.5 * self.hud.dim[1]) |
| 557 | lidar_data = np.fabs(lidar_data) # pylint: disable=E1111 |
| 558 | lidar_data = lidar_data.astype(np.int32) |
| 559 | lidar_data = np.reshape(lidar_data, (-1, 2)) |
| 560 | lidar_img_size = (self.hud.dim[0], self.hud.dim[1], 3) |
| 561 | lidar_img = np.zeros(lidar_img_size) |
| 562 | lidar_img[tuple(lidar_data.T)] = (255, 255, 255) |
| 563 | self.surface = pygame.surfarray.make_surface(lidar_img) |
| 564 | else: |
| 565 | image.convert(self.sensors[self.index][1]) |
| 566 | array = np.frombuffer(image.raw_data, dtype=np.dtype("uint8")) |
| 567 | array = np.reshape(array, (image.height, image.width, 4)) |
| 568 | array = array[:, :, :3] |
| 569 | array = array[:, :, ::-1] |
| 570 | self.surface = pygame.surfarray.make_surface(array.swapaxes(0, 1)) |
| 571 | if self.recording: |
| 572 | image.save_to_disk('_out/%08d' % image.frame) |
| 573 | |
| 574 | |
| 575 | # ============================================================================== |
no test coverage detected