MCPcopy Create free account
hub / github.com/AdaCompNUS/summit / _parse_image

Method _parse_image

PythonAPI/examples/manual_control.py:960–985  ·  view source on GitHub ↗
(weak_self, image)

Source from the content-addressed store, hash-verified

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# ==============================================================================

Callers 1

set_sensorMethod · 0.45

Calls 1

make_surfaceMethod · 0.80

Tested by

no test coverage detected