def enum2dict(obj, key_filter=None):
    """
    PyCapture2 enumerated values are stored as classes making it difficult to
    check the values within them. This function can be used to take a class
    and return it's attributes as a dict.

    Parameters
    ----------
    obj : class
        A PyCapture2.<ENUMERATED VALUE> class
    key_filter : callable, optional
        A callable returning a boolean that can be used to filter the keys of
        the dict. Entries for which the callable return False will be removed.

    Returns
    -------
    D : dict
        Attribute names and values as the dictionary's keys and values.

    Examples
    --------
    >>> D = enum2dict(PyCapture2.VIDEO_MODE, lambda k: k.startswith('VM_'))
    """
    D = dict(obj.__dict__)
    D = dict(filter(lambda elem: not elem[0].startswith('__'), D.items()))
    if (key_filter is not None):
        D = dict(filter(lambda elem: key_filter(elem[0]), D.items()))
    return D