MCPcopy Create free account
hub / github.com/MotrixLab/AiOS / images_to_array

Function images_to_array

detrsmpl/utils/ffmpeg_utils.py:379–489  ·  view source on GitHub ↗

Read a folder of images as an array of (f * h * w * 3). Args: input_folder (str): folder of input images. resolution (Optional[Union[Tuple[int, int], Tuple[float, float]]]: resolution(height, width) of output. Defaults to None. img_format (str, optional)

(
    input_folder: str,
    resolution: Optional[Union[Tuple[int, int], Tuple[float, float]]] = None,
    img_format: str = '%06d.png',
    start: int = 0,
    end: Optional[int] = None,
    remove_raw_files: bool = False,
    disable_log: bool = False,
)

Source from the content-addressed store, hash-verified

377
378
379def images_to_array(
380 input_folder: str,
381 resolution: Optional[Union[Tuple[int, int], Tuple[float, float]]] = None,
382 img_format: str = '%06d.png',
383 start: int = 0,
384 end: Optional[int] = None,
385 remove_raw_files: bool = False,
386 disable_log: bool = False,
387) -> np.ndarray:
388 """
389 Read a folder of images as an array of (f * h * w * 3).
390
391 Args:
392 input_folder (str): folder of input images.
393 resolution (Optional[Union[Tuple[int, int], Tuple[float, float]]]:
394 resolution(height, width) of output. Defaults to None.
395 img_format (str, optional): format of images to be read.
396 Defaults to '%06d.png'.
397 start (int, optional): start frame index. Inclusive.
398 If < 0, will be converted to frame_index range in [0, frame_num].
399 Defaults to 0.
400 end (int, optional): end frame index. Exclusive.
401 Could be positive int or negative int or None.
402 If None, all frames from start till the last frame are included.
403 Defaults to None.
404 remove_raw_files (bool, optional): whether remove raw images.
405 Defaults to False.
406 disable_log (bool, optional): whether close the ffmepg command info.
407 Defaults to False.
408 Raises:
409 FileNotFoundError: check the input path.
410
411 Returns:
412 np.ndarray: shape will be (f * h * w * 3).
413 """
414 check_input_path(
415 input_folder,
416 allowed_suffix=[''],
417 tag='input image folder',
418 path_type='dir')
419
420 input_folderinfo = Path(input_folder)
421
422 temp_input_folder = None
423 if img_format is None:
424 temp_input_folder = os.path.join(input_folderinfo.parent,
425 input_folderinfo.name + '_temp')
426 img_format = images_to_sorted_images(
427 input_folder=input_folder, output_folder=temp_input_folder)
428 input_folder = temp_input_folder
429
430 info = vid_info_reader(f'{input_folder}/{img_format}' % start)
431 width, height = int(info['width']), int(info['height'])
432 if resolution:
433 height, width = resolution
434 else:
435 width, height = int(info['width']), int(info['height'])
436

Callers 2

_prepare_backgroundFunction · 0.90
forwardMethod · 0.90

Calls 5

check_input_pathFunction · 0.90
images_to_sorted_imagesFunction · 0.85
vid_info_readerClass · 0.85
concatenateMethod · 0.80
printFunction · 0.50

Tested by

no test coverage detected