Convert an array to images directly. Args: image_array (np.ndarray): shape should be (f * h * w * 3). output_folder (str): output folder for the images. img_format (str, optional): format of the images. Defaults to '%06d.png'. resolution (Optional[Uni
(
image_array: np.ndarray,
output_folder: str,
img_format: str = '%06d.png',
resolution: Optional[Union[Tuple[int, int], Tuple[float, float]]] = None,
disable_log: bool = False,
)
| 172 | |
| 173 | |
| 174 | def array_to_images( |
| 175 | image_array: np.ndarray, |
| 176 | output_folder: str, |
| 177 | img_format: str = '%06d.png', |
| 178 | resolution: Optional[Union[Tuple[int, int], Tuple[float, float]]] = None, |
| 179 | disable_log: bool = False, |
| 180 | ) -> None: |
| 181 | """Convert an array to images directly. |
| 182 | |
| 183 | Args: |
| 184 | image_array (np.ndarray): shape should be (f * h * w * 3). |
| 185 | output_folder (str): output folder for the images. |
| 186 | img_format (str, optional): format of the images. |
| 187 | Defaults to '%06d.png'. |
| 188 | resolution (Optional[Union[Tuple[int, int], Tuple[float, float]]], |
| 189 | optional): resolution(height, width) of output. |
| 190 | Defaults to None. |
| 191 | disable_log (bool, optional): whether close the ffmepg command info. |
| 192 | Defaults to False. |
| 193 | |
| 194 | Raises: |
| 195 | FileNotFoundError: check output folder. |
| 196 | TypeError: check input array. |
| 197 | |
| 198 | Returns: |
| 199 | None |
| 200 | """ |
| 201 | prepare_output_path( |
| 202 | output_folder, |
| 203 | allowed_suffix=[], |
| 204 | tag='output image folder', |
| 205 | path_type='dir', |
| 206 | overwrite=True) |
| 207 | |
| 208 | if not isinstance(image_array, np.ndarray): |
| 209 | raise TypeError('Input should be np.ndarray.') |
| 210 | assert image_array.ndim == 4 |
| 211 | assert image_array.shape[-1] == 3 |
| 212 | if resolution: |
| 213 | height, width = resolution |
| 214 | else: |
| 215 | height, width = image_array.shape[1], image_array.shape[2] |
| 216 | command = [ |
| 217 | 'ffmpeg', |
| 218 | '-y', # (optional) overwrite output file if it exists |
| 219 | '-f', |
| 220 | 'rawvideo', |
| 221 | '-s', |
| 222 | f'{int(width)}x{int(height)}', # size of one frame |
| 223 | '-pix_fmt', |
| 224 | 'bgr24', # bgr24 for matching OpenCV |
| 225 | '-loglevel', |
| 226 | 'error', |
| 227 | '-threads', |
| 228 | '4', |
| 229 | '-i', |
| 230 | '-', # The input comes from a pipe |
| 231 | '-f', |
nothing calls this directly
no test coverage detected