def imdecode(buf, *args, **kwargs):
    'Decode an image to an NDArray.\n\n    Note: `imdecode` uses OpenCV (not the CV2 Python library).\n    MXNet must have been built with USE_OPENCV=1 for `imdecode` to work.\n\n    Parameters\n    ----------\n    buf : str/bytes or numpy.ndarray\n        Binary image data as string or numpy ndarray.\n    flag : int, optional, default=1\n        1 for three channel color output. 0 for grayscale output.\n    to_rgb : int, optional, default=1\n        1 for RGB formatted output (MXNet default). 0 for BGR formatted output (OpenCV default).\n    out : NDArray, optional\n        Output buffer. Use `None` for automatic allocation.\n\n    Returns\n    -------\n    NDArray\n        An `NDArray` containing the image.\n\n    Example\n    -------\n    >>> with open("flower.jpg", \'rb\') as fp:\n    ...     str_image = fp.read()\n    ...\n    >>> image = mx.img.imdecode(str_image)\n    >>> image\n    <NDArray 224x224x3 @cpu(0)>\n\n    Set `flag` parameter to 0 to get grayscale output\n\n    >>> with open("flower.jpg", \'rb\') as fp:\n    ...     str_image = fp.read()\n    ...\n    >>> image = mx.img.imdecode(str_image, flag=0)\n    >>> image\n    <NDArray 224x224x1 @cpu(0)>\n\n    Set `to_rgb` parameter to 0 to get output in OpenCV format (BGR)\n\n    >>> with open("flower.jpg", \'rb\') as fp:\n    ...     str_image = fp.read()\n    ...\n    >>> image = mx.img.imdecode(str_image, to_rgb=0)\n    >>> image\n    <NDArray 224x224x3 @cpu(0)>\n    '
    if (not isinstance(buf, nd.NDArray)):
        buf = nd.array(np.frombuffer(buf, dtype=np.uint8), dtype=np.uint8)
    return _internal._cvimdecode(buf, *args, **kwargs)
Decode an image to an NDArray.

Note: `imdecode` uses OpenCV (not the CV2 Python library).
MXNet must have been built with USE_OPENCV=1 for `imdecode` to work.

Parameters
----------
buf : str/bytes or numpy.ndarray
    Binary image data as string or numpy ndarray.
flag : int, optional, default=1
    1 for three channel color output. 0 for grayscale output.
to_rgb : int, optional, default=1
    1 for RGB formatted output (MXNet default). 0 for BGR formatted output (OpenCV default).
out : NDArray, optional
    Output buffer. Use `None` for automatic allocation.

Returns
-------
NDArray
    An `NDArray` containing the image.

Example
-------
>>> with open("flower.jpg", 'rb') as fp:
...     str_image = fp.read()
...
>>> image = mx.img.imdecode(str_image)
>>> image
<NDArray 224x224x3 @cpu(0)>

Set `flag` parameter to 0 to get grayscale output

>>> with open("flower.jpg", 'rb') as fp:
...     str_image = fp.read()
...
>>> image = mx.img.imdecode(str_image, flag=0)
>>> image
<NDArray 224x224x1 @cpu(0)>

Set `to_rgb` parameter to 0 to get output in OpenCV format (BGR)

>>> with open("flower.jpg", 'rb') as fp:
...     str_image = fp.read()
...
>>> image = mx.img.imdecode(str_image, to_rgb=0)
>>> image
<NDArray 224x224x3 @cpu(0)>
def imdecode(buf, *args, **kwargs):
    'Decode an image to an NDArray.\n\n    Note: `imdecode` uses OpenCV (not the CV2 Python library).\n    MXNet must have been built with USE_OPENCV=1 for `imdecode` to work.\n\n    Parameters\n    ----------\n    buf : str/bytes or numpy.ndarray\n        Binary image data as string or numpy ndarray.\n    flag : int, optional, default=1\n        1 for three channel color output. 0 for grayscale output.\n    to_rgb : int, optional, default=1\n        1 for RGB formatted output (MXNet default). 0 for BGR formatted output (OpenCV default).\n    out : NDArray, optional\n        Output buffer. Use `None` for automatic allocation.\n\n    Returns\n    -------\n    NDArray\n        An `NDArray` containing the image.\n\n    Example\n    -------\n    >>> with open("flower.jpg", \'rb\') as fp:\n    ...     str_image = fp.read()\n    ...\n    >>> image = mx.img.imdecode(str_image)\n    >>> image\n    <NDArray 224x224x3 @cpu(0)>\n\n    Set `flag` parameter to 0 to get grayscale output\n\n    >>> with open("flower.jpg", \'rb\') as fp:\n    ...     str_image = fp.read()\n    ...\n    >>> image = mx.img.imdecode(str_image, flag=0)\n    >>> image\n    <NDArray 224x224x1 @cpu(0)>\n\n    Set `to_rgb` parameter to 0 to get output in OpenCV format (BGR)\n\n    >>> with open("flower.jpg", \'rb\') as fp:\n    ...     str_image = fp.read()\n    ...\n    >>> image = mx.img.imdecode(str_image, to_rgb=0)\n    >>> image\n    <NDArray 224x224x3 @cpu(0)>\n    '
    if (not isinstance(buf, nd.NDArray)):
        buf = nd.array(np.frombuffer(buf, dtype=np.uint8), dtype=np.uint8)
    return _internal._cvimdecode(buf, *args, **kwargs)