Shortcuts

mmcv.image.imfrombytes

mmcv.image.imfrombytes(content: bytes, flag: str = 'color', channel_order: str = 'bgr', backend: Optional[str] = None)numpy.ndarray[source]

Read an image from bytes.

Parameters
  • content (bytes) – Image bytes got from files or other streams.

  • flag (str) – Same as imread().

  • channel_order (str) – The channel order of the output, candidates are ‘bgr’ and ‘rgb’. Default to ‘bgr’.

  • backend (str | None) – The image decoding backend type. Options are cv2, pillow, turbojpeg, tifffile, None. If backend is None, the global imread_backend specified by mmcv.use_backend() will be used. Default: None.

Returns

Loaded image array.

Return type

ndarray

Examples

>>> img_path = '/path/to/img.jpg'
>>> with open(img_path, 'rb') as f:
>>>     img_buff = f.read()
>>> img = mmcv.imfrombytes(img_buff)
>>> img = mmcv.imfrombytes(img_buff, flag='color', channel_order='rgb')
>>> img = mmcv.imfrombytes(img_buff, backend='pillow')
>>> img = mmcv.imfrombytes(img_buff, backend='cv2')