Пример #1
0
 def test_should_return_batches_equivalent_to_number_of_frames(self):
     video_info = VideoMetaInfo('dummy.avi', 10, VideoFormat.MPEG)
     video_loader = SimpleVideoLoader(video_info)
     batches = list(video_loader.load())
     dummy_frames = list(self.create_dummy_frames())
     self.assertEqual(len(batches), NUM_FRAMES)
     self.assertEqual(dummy_frames, [batch.frames[0] for batch in batches])
 def __init__(self, node: StoragePlan):
     super().__init__(node)
     self.storage = SimpleVideoLoader(node.video,
                                      batch_size=node.batch_size,
                                      skip_frames=node.skip_frames,
                                      limit=node.limit,
                                      offset=node.offset)
Пример #3
0
 def test_should_return_single_batch_if_batch_size_equal_to_no_of_frames(
         self):
     video_info = VideoMetaInfo('dummy.avi', 10, VideoFormat.MPEG)
     video_loader = SimpleVideoLoader(video_info, batch_size=NUM_FRAMES)
     dummy_frames = list(
         self.create_dummy_frames(filters=[i for i in range(NUM_FRAMES)]))
     batches = list(video_loader.load())
     self.assertEqual(1, len(batches))
     self.assertEqual(dummy_frames, list(batches[0].frames))
Пример #4
0
 def test_should_return_only_few_frames_when_limit_is_specified(self):
     video_info = VideoMetaInfo('dummy.avi', 10, VideoFormat.MPEG)
     limit = 4
     video_loader = SimpleVideoLoader(video_info, limit=limit)
     dummy_frames = list(
         self.create_dummy_frames(filters=[i for i in range(limit)]))
     batches = list(video_loader.load())
     self.assertEqual(limit, len(batches))
     self.assertEqual(dummy_frames, [batch.frames[0] for batch in batches])
Пример #5
0
 def test_should_skip_first_two_frames_with_offset_two(self):
     video_info = VideoMetaInfo('dummy.avi', 10, VideoFormat.MPEG)
     video_loader = SimpleVideoLoader(video_info, offset=2)
     dummy_frames = list(
         self.create_dummy_frames(filters=[i
                                           for i in range(2, NUM_FRAMES)]))
     batches = list(video_loader.load())
     self.assertEqual(NUM_FRAMES - 2, len(batches))
     self.assertEqual(dummy_frames, [batch.frames[0] for batch in batches])
Пример #6
0
 def test_should_return_half_then_number_of_batches_with_skip_of_two(self):
     video_info = VideoMetaInfo('dummy.avi', 10, VideoFormat.MPEG)
     video_loader = SimpleVideoLoader(video_info, skip_frames=2)
     batches = list(video_loader.load())
     dummy_frames = list(
         self.create_dummy_frames(
             filters=[i * 2 for i in range(NUM_FRAMES // 2)]))
     self.assertEqual(len(batches), NUM_FRAMES / 2)
     self.assertEqual(dummy_frames, [batch.frames[0] for batch in batches])
Пример #7
0
 def convert(statement_list):
     if len(statement_list) > 1 or len(statement_list) == 0:
         print('statement list must be length 1 and it was len: {}'.format(len(statement_list)))
     else:
         statement = statement_list[0]
         # Need to Create the table and projection
         from_stuff = statement.from_table
         meta1 = VideoMetaInfo(file=from_stuff.table_info.table_name, c_format=VideoFormat.MOV, fps=30)
         video1 = SimpleVideoLoader(video_metadata=meta1)
         t1 = TableRef(video=video1, table_info=TableInfo(table_name=from_stuff.table_info.table_name))
         # Creating projection (root)
         projection_output = [target.col_name for target in statement.target_list]
         root = LogicalProjectionPlan(videos=[video1], column_ids=projection_output, foreign_column_ids=[])
         where_stuff = statement.where_clause
         print(where_stuff)
         # Need to create the sigma plan
         if where_stuff is not None:
             # Creating a select Node
             select_node = SeqScanPlan(predicate=where_stuff, column_ids=projection_output, videos=[video1], foreign_column_ids=[])
             root.set_children(select_node)
             select_node.parent=root
             select_node.set_children([t1])
             t1.parent=select_node
         else:
             root.set_children([t1])
             t1.parent = root
         return root
class DiskStorageExecutor(AbstractStorageExecutor):
    """
    This is a simple disk based executor. It assumes that frames are
    directly being read from the disk(video file).

    Note: For a full fledged deployment this might be replaced with a
    Transaction manager which keeps track of the frames.
    """
    def __init__(self, node: StoragePlan):
        super().__init__(node)
        self.storage = SimpleVideoLoader(node.video,
                                         batch_size=node.batch_size,
                                         skip_frames=node.skip_frames,
                                         limit=node.limit,
                                         offset=node.offset)

    def validate(self):
        pass

    def next(self) -> Iterator[FrameBatch]:
        for batch in self.storage.load():
            yield batch