def rgb2bgr(img: Union[np.ndarray, Image]) -> np.ndarray:
    """
    Convert an RGB image into ndarray of mode BGR.

    Args:
        img (`Union[np.ndarray, 'towhee.types.Image']`):
            An RGB image either in the form of ndarray or towhee's Image.

    Returns:
        (`np.ndarray`)
            An ndarray in the mode of BGR.
    """
    if isinstance(img, Image):
        if not img.mode.upper() == 'RGB':
            raise ValueError('The input image should be RGB mode.')
        else:
            rgb_img = to_ndarray(img)

    elif isinstance(img, np.ndarray):
        rgb_img = img

    else:
        raise TypeError('Input image should either be an `np.ndarray` or a `towhee.types.Image`.')

    bgr_img = cv2.cvtColor(rgb_img, cv2.COLOR_RGB2BGR)

    return bgr_img
Convert an RGB image into ndarray of mode BGR.

Args:
img (`Union[np.ndarray, 'towhee.types.Image']`):
An RGB image either in the form of ndarray or towhee's Image.

Returns:
(`np.ndarray`)
An ndarray in the mode of BGR.
towhee/utils/ndarray_utils.py