Ejemplo n.º 1
0
 def _convert_camera_frame_to_image_dict(
         self, camera_frame: imagery_pb2.CameraFrame):
     """Converts the camera frame to an image dictionary."""
     # Each camera frame might contain multiple image channels, such as rgb and
     # depth.
     images = {}
     for image_name, image_proto in camera_frame.images.items():
         image_array = imagery_utils.convert_image_to_array(image_proto)
         images[image_name] = image_array
     return images
Ejemplo n.º 2
0
    def test_convert_gray_16bit_images(self):
        image = imagery_pb2.Image(
            height_px=3,
            width_px=2,
            image_format=imagery_pb2.Image.IMAGE_FORMAT_GRAY_HW_16U,
            content=b'AABBCCAABBCC',
        )

        image_array = imagery_utils.convert_image_to_array(image)

        self.assertEqual(image_array.dtype, np.uint16)
        self.assertEqual(image_array.shape, (image.height_px, image.width_px))
        self.assertEqual(image_array[0, 1], struct.unpack(b'<H', b'BB'))
        self.assertEqual(image_array[2, 1], struct.unpack(b'<H', b'CC'))
Ejemplo n.º 3
0
    def test_convert_gray_32bit_images(self):
        image = imagery_pb2.Image(
            height_px=2,
            width_px=3,
            image_format=imagery_pb2.Image.IMAGE_FORMAT_GRAY_HW_32F,
            content=b'AAAABBBBCCCCAAAABBBBCCCC',
        )

        image_array = imagery_utils.convert_image_to_array(image)

        self.assertEqual(image_array.dtype, np.float32)
        self.assertEqual(image_array.shape, (image.height_px, image.width_px))
        self.assertEqual(image_array[0, 2], struct.unpack(b'<f', b'CCCC'))
        self.assertEqual(image_array[1, 1], struct.unpack(b'<f', b'BBBB'))
Ejemplo n.º 4
0
    def test_convert_rgb_images(self):
        image = imagery_pb2.Image(
            height_px=2,
            width_px=2,
            image_format=imagery_pb2.Image.IMAGE_FORMAT_RGB_HWC_8U,
            content=b'ABCABCABCABC',
        )

        image_array = imagery_utils.convert_image_to_array(image)

        self.assertEqual(image_array.dtype, np.uint8)
        self.assertEqual(image_array.shape,
                         (image.height_px, image.width_px, 3))
        self.assertEqual(image_array[0, 0, 0], ord('A'))
        self.assertEqual(image_array[1, 1, 2], ord('C'))
Ejemplo n.º 5
0
    def test_convert_bgra_images(self):
        image = imagery_pb2.Image(
            height_px=2,
            width_px=2,
            image_format=imagery_pb2.Image.IMAGE_FORMAT_BGRA_HWC_8U,
            content=b'ABCDABCDABCDABCD',
        )

        image_array = imagery_utils.convert_image_to_array(image)

        self.assertEqual(image_array.dtype, np.uint8)
        self.assertEqual(image_array.shape,
                         (image.height_px, image.width_px, 4))
        self.assertEqual(image_array[0, 0, 0], ord('A'))
        self.assertEqual(image_array[1, 0, 3], ord('D'))
Ejemplo n.º 6
0
 def test_unspecified_image_format(self):
     image = imagery_pb2.Image()
     with self.assertRaises(ValueError):
         imagery_utils.convert_image_to_array(image)