code: 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
  
file_path: towhee/towhee/utils/ndarray_utils.py
imports: import glob
  from pathlib import Path, PosixPath
  from typing import Union
  import numpy
  from io import BytesIO
  from zipfile import ZipFile
  from urllib.request import urlopen
  from towhee.types import Image
  from towhee.utils.repo_normalize import RepoNormalize
  from towhee.utils.cv2_utils import cv2
label_desc: Use image node_id 5 for calling a global function with example usage: rgb2bgr(img) and returns: bgr_img