Example #1
0
    def test_can_be_compared_without_loading_images(self):
        images = []
        for idx in range(10):
            img = CountedImage(
                pixels=np.random.uniform(0, 255, (32, 32, 3)),
                image_group='test',
                metadata=make_metadata(idx),
            )
            img.save()
            images.append(img)

        collection = ic.ImageCollection(
            images=images,
            timestamps=[1.1 * idx for idx in range(10)],
            sequence_type=ImageSequenceType.SEQUENTIAL)
        collection.save()
        collection = ic.ImageCollection(
            images=images,
            timestamps=[1.2 * idx for idx in range(10)],
            sequence_type=ImageSequenceType.SEQUENTIAL)
        collection.save()
        CountedImage.instance_count = 0

        # Load all the entities
        all_entities = list(ic.ImageCollection.objects.all())
        self.assertEqual(len(all_entities), 2)
        self.assertNotEqual(all_entities[0], all_entities[1])
        self.assertEqual(CountedImage.instance_count, 0)

        # Check actually reading the images loads them
        _ = all_entities[0].images[0]
        self.assertEqual(CountedImage.instance_count, 10)

        all_entities[0].delete()
        all_entities[1].delete()
Example #2
0
    def test_infers_properties_from_mono_images(self):
        images = [make_image(idx, depth=None) for idx in range(10)]

        collection = ic.ImageCollection(
            images=images,
            timestamps=[1.1 * idx for idx in range(10)],
            sequence_type=ImageSequenceType.SEQUENTIAL)
        self.assertEqual(images[0].image_group, collection.image_group)
        self.assertFalse(collection.is_depth_available)
        self.assertTrue(collection.is_normals_available)
        self.assertFalse(collection.is_stereo_available)
        self.assertTrue(collection.is_labels_available)
        self.assertFalse(collection.is_masks_available)

        self.assertEqual(collection.camera_intrinsics,
                         images[0].metadata.intrinsics)
        self.assertIsNone(collection.stereo_offset)
        self.assertIsNone(collection.right_camera_intrinsics)

        images = [
            make_image(idx,
                       normals=None,
                       metadata=make_metadata(
                           idx,
                           labelled_objects=[
                               imeta.MaskedObject(
                                   ('class_1', ), 152, 239, 14, 78,
                                   tf.Transform(location=(123, -45, 23),
                                                rotation=(0.5, 0.23, 0.1)),
                                   'LabelledObject-18569',
                                   np.random.choice((True, False),
                                                    size=(78, 14)))
                           ])) for idx in range(10)
        ]

        collection = ic.ImageCollection(
            images=images,
            timestamps=[1.1 * idx for idx in range(10)],
            sequence_type=ImageSequenceType.SEQUENTIAL)
        self.assertTrue(collection.is_depth_available)
        self.assertFalse(collection.is_normals_available)
        self.assertFalse(collection.is_stereo_available)
        self.assertTrue(collection.is_labels_available)
        self.assertTrue(collection.is_masks_available)

        self.assertEqual(collection.camera_intrinsics,
                         images[0].metadata.intrinsics)
        self.assertIsNone(collection.stereo_offset)
        self.assertIsNone(collection.right_camera_intrinsics)
Example #3
0
    def test_stores_and_loads_stereo(self):
        images = []
        for idx in range(10):
            img = make_stereo_image(idx)
            img.save()
            images.append(img)

        collection = ic.ImageCollection(
            images=images,
            timestamps=[1.1 * idx for idx in range(10)],
            sequence_type=ImageSequenceType.SEQUENTIAL,
            is_depth_available=True,
            is_normals_available=True,
            is_stereo_available=False,
            is_labels_available=True,
            is_masks_available=False,
            camera_intrinsics=images[0].metadata.intrinsics,
            stereo_offset=images[0].left_camera_pose.find_relative(
                images[0].right_camera_pose),
            right_camera_intrinsics=images[0].right_metadata.intrinsics,
            dataset='TestSequences',
            sequence_name='Sequence1',
            trajectory_id='simple-motion')
        collection.save()

        # Load all the entities
        all_entities = list(ic.ImageCollection.objects.all())
        self.assertGreaterEqual(len(all_entities), 1)
        self.assertEqual(all_entities[0], collection)
        all_entities[0].delete()
Example #4
0
 def test_framerate_returns_average_time_interval_between_frames(self):
     images = [make_image(idx, depth=None) for idx in range(10)]
     collection = ic.ImageCollection(
         images=images,
         timestamps=[3.2 + 0.25 * idx for idx in range(10)],
         sequence_type=ImageSequenceType.SEQUENTIAL)
     self.assertEqual(0.25, collection.average_timestep)
Example #5
0
    def test_chooses_a_default_trajectory_id(self):
        images = [make_image(idx, depth=None) for idx in range(10)]

        collection = ic.ImageCollection(
            images=images,
            timestamps=[1.1 * idx for idx in range(10)],
            sequence_type=ImageSequenceType.SEQUENTIAL,
            dataset='TestData',
            sequence_name='Sequence1')
        self.assertEqual('TestData:Sequence1', collection.trajectory_id)
Example #6
0
    def test_required_fields_are_required(self):
        images = []
        for idx in range(10):
            img = make_image(idx)
            img.save()
            images.append(img)

        # Missing sequence type
        collection = ic.ImageCollection(
            images=images, timestamps=[1.1 * idx for idx in range(10)])
        with self.assertRaises(ValidationError):
            collection.save()

        # Missing images
        collection = ic.ImageCollection(
            timestamps=[1.1 * idx for idx in range(10)],
            sequence_type=ImageSequenceType.SEQUENTIAL)
        with self.assertRaises(ValidationError):
            collection.save()

        # Missing timestamps
        collection = ic.ImageCollection(
            images=images, sequence_type=ImageSequenceType.SEQUENTIAL)
        with self.assertRaises(ValidationError):
            collection.save()

        # blank image_group
        collection = ic.ImageCollection(
            images=images,
            timestamps=[1.1 * idx for idx in range(10)],
            sequence_type=ImageSequenceType.SEQUENTIAL,
        )
        collection.image_group = None  # Explicitly clear because it is inferred by the constructor
        with self.assertRaises(ValidationError):
            collection.save()

        # Empty images and timestamps
        collection = ic.ImageCollection(
            images=[],
            timestamps=[],
            sequence_type=ImageSequenceType.SEQUENTIAL)
        with self.assertRaises(ValidationError):
            collection.save()
Example #7
0
 def test_get_columns_returns_column_list(self):
     images = [make_image(idx, depth=None) for idx in range(10)]
     collection = ic.ImageCollection(
         images=images,
         timestamps=[1.1 * idx for idx in range(10)],
         sequence_type=ImageSequenceType.SEQUENTIAL)
     self.assertEqual({
         'dataset',
         'sequence_name',
         'trajectory_id',
     }, collection.get_columns())
Example #8
0
 def test_get_properties_returns_only_requested_columns_that_exist(self):
     dataset = 'my dataset'
     sequence_name = 'this is a sequence'
     trajectory_id = 'trajectory 6'
     images = [make_image(idx, depth=None) for idx in range(10)]
     collection = ic.ImageCollection(
         images=images,
         timestamps=[1.1 * idx for idx in range(10)],
         sequence_type=ImageSequenceType.SEQUENTIAL,
         dataset=dataset,
         sequence_name=sequence_name,
         trajectory_id=trajectory_id)
     self.assertEqual({'dataset': dataset},
                      collection.get_properties({'dataset',
                                                 'not_a_column'}))
Example #9
0
 def test_iterates_over_timestamps_and_images_in_timestamp_order(self):
     pairs = [(10 - 0.8 * idx, make_image(idx, depth=None))
              for idx in range(10)]
     collection = ic.ImageCollection(
         images=[pair[1] for pair in pairs],
         timestamps=[pair[0] for pair in pairs],
         sequence_type=ImageSequenceType.SEQUENTIAL)
     pairs = sorted(pairs, key=itemgetter(0))
     prev_timestamp = None
     for idx, (timestamp, image) in enumerate(collection):
         self.assertEqual(pairs[idx][0], timestamp)
         self.assertEqual(pairs[idx][1], image)
         if prev_timestamp is not None:
             self.assertGreater(timestamp, prev_timestamp)
         prev_timestamp = timestamp
Example #10
0
 def test_get_properties_returns_the_value_of_all_columns(self):
     dataset = 'my dataset'
     sequence_name = 'this is a sequence'
     trajectory_id = 'trajectory 6'
     images = [make_image(idx, depth=None) for idx in range(10)]
     collection = ic.ImageCollection(
         images=images,
         timestamps=[1.1 * idx for idx in range(10)],
         sequence_type=ImageSequenceType.SEQUENTIAL,
         dataset=dataset,
         sequence_name=sequence_name,
         trajectory_id=trajectory_id)
     self.assertEqual(
         {
             'dataset': dataset,
             'sequence_name': sequence_name,
             'trajectory_id': trajectory_id
         }, collection.get_properties())
Example #11
0
    def test_load_minimal_returns_object_without_images(self):
        images = []
        for idx in range(10):
            img = CountedImage(
                pixels=np.random.uniform(0, 255, (32, 32, 3)),
                image_group='test',
                metadata=make_metadata(idx),
            )
            img.save()
            images.append(img)

        collection = ic.ImageCollection(
            images=images,
            timestamps=[1.1 * idx for idx in range(10)],
            sequence_type=ImageSequenceType.SEQUENTIAL)
        collection.save()

        collection_id = collection.pk
        sequence_type = collection.sequence_type
        image_group = collection.image_group
        is_depth_available = collection.is_depth_available
        is_normals_available = collection.is_normals_available
        is_stereo_available = collection.is_stereo_available
        is_labels_available = collection.is_labels_available
        is_masks_available = collection.is_masks_available
        camera_intrinsics = collection.camera_intrinsics

        del images
        del img
        del collection
        CountedImage.instance_count = 0

        collection = ic.ImageCollection.load_minimal(collection_id)
        self.assertEqual(0, CountedImage.instance_count)
        self.assertEqual(sequence_type, collection.sequence_type)
        self.assertEqual(image_group, collection.image_group)
        self.assertEqual(is_depth_available, collection.is_depth_available)
        self.assertEqual(is_normals_available, collection.is_normals_available)
        self.assertEqual(is_stereo_available, collection.is_stereo_available)
        self.assertEqual(is_labels_available, collection.is_labels_available)
        self.assertEqual(is_masks_available, collection.is_masks_available)
        self.assertEqual(camera_intrinsics, collection.camera_intrinsics)
        self.assertEqual([], collection.images)
        self.assertEqual([], collection.timestamps)
Example #12
0
    def test_stores_and_loads_mono_args(self):
        images = []
        for idx in range(10):
            img = make_image(idx)
            img.save()
            images.append(img)

        collection = ic.ImageCollection(images,
                                        [1.1 * idx for idx in range(10)],
                                        ImageSequenceType.SEQUENTIAL, True,
                                        True, False, True, False,
                                        images[0].metadata.intrinsics)
        collection.save()

        # Load all the entities
        all_entities = list(ic.ImageCollection.objects.all())
        self.assertGreaterEqual(len(all_entities), 1)
        self.assertEqual(all_entities[0], collection)
        all_entities[0].delete()
Example #13
0
    def test_infers_properties_from_stereo_images(self):
        images = [make_stereo_image(idx, depth=None) for idx in range(10)]

        collection = ic.ImageCollection(
            images=images,
            timestamps=[1.1 * idx for idx in range(10)],
            sequence_type=ImageSequenceType.SEQUENTIAL)
        self.assertEqual(images[0].image_group, collection.image_group)
        self.assertFalse(collection.is_depth_available)
        self.assertTrue(collection.is_normals_available)
        self.assertTrue(collection.is_stereo_available)
        self.assertTrue(collection.is_labels_available)
        self.assertFalse(collection.is_masks_available)

        self.assertEqual(collection.camera_intrinsics,
                         images[0].metadata.intrinsics)
        self.assertEqual(
            collection.stereo_offset, images[0].left_camera_pose.find_relative(
                images[0].right_camera_pose))
        self.assertEqual(collection.right_camera_intrinsics,
                         images[0].right_metadata.intrinsics)
Example #14
0
    def test_constructor_works_with_mixed_args(self):
        images = [make_image(idx, depth=None) for idx in range(10)]

        arguments = [('images', images),
                     ('timestamps', [1.1 * idx for idx in range(10)]),
                     ('sequence_type', ImageSequenceType.SEQUENTIAL),
                     ('image_group', images[0].image_group),
                     ('is_depth_available', True),
                     ('is_normals_available', False),
                     ('is_stereo_available', False),
                     ('is_labels_available', False),
                     ('is_masks_available', True),
                     ('camera_intrinsics', images[0].metadata.intrinsics)]
        for idx in range(len(arguments) + 1):
            collection = ic.ImageCollection(
                *(v for _, v in arguments[:idx]),
                **{k: v
                   for k, v in arguments[idx:]})

            # Check it got assigned correctly
            for name, value in arguments:
                self.assertEqual(value, getattr(collection, name))