mmcv/visualization/color.py
def color_val(color):
    """Convert various input to color tuples.

    Args:
        color (:obj:`Color`/str/tuple/int/ndarray): Color inputs

    Returns:
        tuple[int]: A tuple of 3 integers indicating BGR channels.
    """
    if is_str(color):
        return Color[color].value
    elif isinstance(color, Color):
        return color.value
    elif isinstance(color, tuple):
        assert len(color) == 3
        for channel in color:
            assert channel >= 0 and channel <= 255
        return color
    elif isinstance(color, int):
        assert color >= 0 and color <= 255
        return color, color, color
    elif isinstance(color, np.ndarray):
        assert color.ndim == 1 and color.size == 3
        assert np.all((color >= 0) & (color <= 255))
        color = color.astype(np.uint8)
        return tuple(color)
    else:
        raise TypeError('Invalid type for color: {}'.format(type(color)))
def color_val(color):
    if is_str(color):
        return Color[color].value
    elif isinstance(color, Color):
        return color.value
    elif isinstance(color, tuple):
        assert len(color) == 3
        for channel in color:
            assert channel >= 0 and channel <= 255
        return color
    elif isinstance(color, int):
        assert color >= 0 and color <= 255
        return color, color, color
    elif isinstance(color, np.ndarray):
        assert color.ndim == 1 and color.size == 3
        assert np.all((color >= 0) & (color <= 255))
        color = color.astype(np.uint8)
        return tuple(color)
    else:
        raise TypeError('Invalid type for color: {}'.format(type(color)))
def color_val ( color ) : if is_str ( color ) : return Color [ color ] . value elif isinstance ( color , Color ) : return color . value elif isinstance ( color , tuple ) : assert len ( color ) == 3 for channel in color : assert channel >= 0 and channel <= 255 return color elif isinstance ( color , int ) : assert color >= 0 and color <= 255 return color , color , color elif isinstance ( color , np . ndarray ) : assert color . ndim == 1 and color . size == 3 assert np . all ( ( color >= 0 ) & ( color <= 255 ) ) color = color . astype ( np . uint8 ) return tuple ( color ) else : raise TypeError ( 'Invalid type for color: {}' . format ( type ( color ) ) )
Convert various input to color tuples.

    Args:
        color (:obj:`Color`/str/tuple/int/ndarray): Color inputs

    Returns:
        tuple[int]: A tuple of 3 integers indicating BGR channels.
Convert various input to color tuples .