def flip_channels(img):
    """Flips the order of channels in an image; eg, BGR <-> RGB.

    This function assumes the image is a numpy.array (what's returned by cv2
    function calls) and uses the numpy re-ordering methods. The number of
    channels does not matter.
    If the image array is strictly 2D, no re-ordering is possible and the
    original data is returned untouched.
    """
    if len(img.shape) == 2:
        return img;
    return img[:,:,::-1]