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

Method _parse_image

PythonAPI/examples/manual_control_rss.py:838–863  ·  view source on GitHub ↗
(weak_self, image)

Source from the content-addressed store, hash-verified

836
837 @staticmethod
838 def _parse_image(weak_self, image):
839 self = weak_self()
840 if not self:
841 return
842 if self.sensors[self.index][0].startswith('sensor.lidar'):
843 points = np.frombuffer(image.raw_data, dtype=np.dtype('f4'))
844 points = np.reshape(points, (int(points.shape[0] / 3), 3))
845 lidar_data = np.array(points[:, :2])
846 lidar_data *= min(self.hud.dim) / 100.0
847 lidar_data += (0.5 * self.hud.dim[0], 0.5 * self.hud.dim[1])
848 lidar_data = np.fabs(lidar_data) # pylint: disable=E1111
849 lidar_data = lidar_data.astype(np.int32)
850 lidar_data = np.reshape(lidar_data, (-1, 2))
851 lidar_img_size = (self.hud.dim[0], self.hud.dim[1], 3)
852 lidar_img = np.zeros((lidar_img_size), dtype = int)
853 lidar_img[tuple(lidar_data.T)] = (255, 255, 255)
854 self.surface = pygame.surfarray.make_surface(lidar_img)
855 else:
856 image.convert(self.sensors[self.index][1])
857 array = np.frombuffer(image.raw_data, dtype=np.dtype("uint8"))
858 array = np.reshape(array, (image.height, image.width, 4))
859 array = array[:, :, :3]
860 array = array[:, :, ::-1]
861 self.surface = pygame.surfarray.make_surface(array.swapaxes(0, 1))
862 if self.recording:
863 image.save_to_disk('_out/%08d' % image.frame)
864
865
866# ==============================================================================

Callers 1

set_sensorMethod · 0.45

Calls 1

make_surfaceMethod · 0.80

Tested by

no test coverage detected