| 94 | |
| 95 | |
| 96 | class VideoData: |
| 97 | def __init__(self, video_file, image_folder, **kwargs): |
| 98 | if video_file is not None: |
| 99 | self.data_type = "video" |
| 100 | self.data = LowMemoryVideo(video_file, **kwargs) |
| 101 | elif image_folder is not None: |
| 102 | self.data_type = "images" |
| 103 | self.data = LowMemoryImageFolder(image_folder, **kwargs) |
| 104 | else: |
| 105 | raise ValueError("Cannot open video or image folder") |
| 106 | self.length = None |
| 107 | self.height = None |
| 108 | self.width = None |
| 109 | |
| 110 | def raw_data(self): |
| 111 | frames = [] |
| 112 | for i in range(self.__len__()): |
| 113 | frames.append(self.__getitem__(i)) |
| 114 | return frames |
| 115 | |
| 116 | def set_length(self, length): |
| 117 | self.length = length |
| 118 | |
| 119 | def set_shape(self, height, width): |
| 120 | self.height = height |
| 121 | self.width = width |
| 122 | |
| 123 | def __len__(self): |
| 124 | if self.length is None: |
| 125 | return len(self.data) |
| 126 | else: |
| 127 | return self.length |
| 128 | |
| 129 | def shape(self): |
| 130 | if self.height is not None and self.width is not None: |
| 131 | return self.height, self.width |
| 132 | else: |
| 133 | height, width, _ = self.__getitem__(0).shape |
| 134 | return height, width |
| 135 | |
| 136 | def __getitem__(self, item): |
| 137 | frame = self.data.__getitem__(item) |
| 138 | height, width, _ = frame.shape |
| 139 | if self.height is not None and self.width is not None: |
| 140 | if self.height != height or self.width != width: |
| 141 | frame = Image.fromarray(frame).resize((self.width, self.height)) |
| 142 | frame = np.array(frame) |
| 143 | return frame |
| 144 | |
| 145 | def __del__(self): |
| 146 | pass |
no outgoing calls
no test coverage detected