def make_instance(self, *args, **kwargs): kwargs = du.defaults( kwargs, { 'inner': make_image_collection(), 'repeats': 3, 'type_override': core.sequence_type.ImageSequenceType.SEQUENTIAL }) return looper.LoopingCollection(*args, **kwargs)
def test_can_override_sequence_type(self): inner = mock.create_autospec(core.image_collection.ImageCollection) inner.get_next_image.return_value = (make_image(), 10) inner.sequence_type.return_value = core.sequence_type.ImageSequenceType.NON_SEQUENTIAL subject = looper.LoopingCollection( inner, 3, type_override=core.sequence_type.ImageSequenceType.SEQUENTIAL) self.assertEqual(core.sequence_type.ImageSequenceType.SEQUENTIAL, subject.sequence_type)
def test_returns_inner_images_in_order(self): img1 = make_image(data=np.array([[1, 2, 3], [4, 5, 6], [7, 8, 9]])) img2 = make_image( data=np.array([[11, 12, 13], [14, 15, 16], [17, 18, 19]])) collection = make_image_collection(images={1: img1, 2: img2}) subject = looper.LoopingCollection(collection, 3) subject.begin() for _ in range(3): img, _ = subject.get_next_image() self.assertNPEqual([[1, 2, 3], [4, 5, 6], [7, 8, 9]], img.data) img, _ = subject.get_next_image() self.assertNPEqual([[11, 12, 13], [14, 15, 16], [17, 18, 19]], img.data) self.assertTrue(subject.is_complete())
def test_singe_repeat_is_same_as_inner_collection(self): images = { idx + np.random.uniform(-0.2, 0.2): make_image( data=np.random.randint(0, 255, (10, 10, 3), dtype=np.uint8)) for idx in range(10) } collection = make_image_collection(images=images) subject = looper.LoopingCollection(collection, 1) self.assertEqual(10, len(subject)) img_count = 0 prev_stamp = -1 subject.begin() while not subject.is_complete(): img, stamp = subject.get_next_image() self.assertIn(stamp, images) self.assertNPEqual(images[stamp].data, img.data) self.assertGreater(stamp, prev_stamp) prev_stamp = stamp img_count += 1 self.assertEqual(img_count, 10)
def test_stacks_stamp_on_subsequent_loops(self): images = { idx + np.random.uniform(-0.2, 0.2): make_image( data=np.random.randint(0, 255, (10, 10, 3), dtype=np.uint8)) for idx in range(10) } collection = make_image_collection(images=images) subject = looper.LoopingCollection(collection, 2) timestamps = sorted(images.keys()) max_timestamp = max(timestamps) self.assertEqual(20, len(subject)) subject.begin() for idx in range(10): _, stamp = subject.get_next_image() self.assertEqual(timestamps[idx], stamp, "Failed on image {0}".format(idx)) for idx in range(10): _, stamp = subject.get_next_image() self.assertEqual(timestamps[idx] + max_timestamp, stamp) self.assertTrue(subject.is_complete())
def test_begin_calls_begin_on_inner(self): inner = mock.create_autospec(core.image_collection.ImageCollection) inner.get_next_image.return_value = (make_image(), 10) subject = looper.LoopingCollection(inner, 3) subject.begin() self.assertTrue(inner.begin.called)