(weak_self, image)
| 958 | |
| 959 | @staticmethod |
| 960 | def _parse_image(weak_self, image): |
| 961 | self = weak_self() |
| 962 | if not self: |
| 963 | return |
| 964 | if self.sensors[self.index][0].startswith('sensor.lidar'): |
| 965 | points = np.frombuffer(image.raw_data, dtype=np.dtype('f4')) |
| 966 | points = np.reshape(points, (int(points.shape[0] / 3), 3)) |
| 967 | lidar_data = np.array(points[:, :2]) |
| 968 | lidar_data *= min(self.hud.dim) / 100.0 |
| 969 | lidar_data += (0.5 * self.hud.dim[0], 0.5 * self.hud.dim[1]) |
| 970 | lidar_data = np.fabs(lidar_data) # pylint: disable=E1111 |
| 971 | lidar_data = lidar_data.astype(np.int32) |
| 972 | lidar_data = np.reshape(lidar_data, (-1, 2)) |
| 973 | lidar_img_size = (self.hud.dim[0], self.hud.dim[1], 3) |
| 974 | lidar_img = np.zeros((lidar_img_size), dtype = int) |
| 975 | lidar_img[tuple(lidar_data.T)] = (255, 255, 255) |
| 976 | self.surface = pygame.surfarray.make_surface(lidar_img) |
| 977 | else: |
| 978 | image.convert(self.sensors[self.index][1]) |
| 979 | array = np.frombuffer(image.raw_data, dtype=np.dtype("uint8")) |
| 980 | array = np.reshape(array, (image.height, image.width, 4)) |
| 981 | array = array[:, :, :3] |
| 982 | array = array[:, :, ::-1] |
| 983 | self.surface = pygame.surfarray.make_surface(array.swapaxes(0, 1)) |
| 984 | if self.recording: |
| 985 | image.save_to_disk('_out/%08d' % image.frame) |
| 986 | |
| 987 | |
| 988 | # ============================================================================== |
no test coverage detected