Exemplo n.º 1
0
def autoCreateCapture(src, timestamps=None, timebase=None):
    preferred_idx = 0
    # checking src and handling all cases:
    src_type = type(src)

    if src_type is tuple:
        src, preferred_idx = src
        src_type = type(src)

    #looking for attached cameras that match the suggested names
    if src_type is list:
        matching_devices = []
        for device in device_list():
            if any([s in device['name'] for s in src]):
                matching_devices.append(device)

        if len(matching_devices) > preferred_idx:
            logger.info(
                'Found %s as devices that match the src string pattern Using the %s match.'
                % ([d['name'] for d in matching_devices],
                   ('first', 'second', 'third', 'fourth')[preferred_idx]))
        else:
            if len(matching_devices) == 0:
                logger.error('No device found that matched %s' % src)
            else:
                logger.error('Not enough devices found that matched %s' % src)
            return FakeCapture(timebase=timebase)

        cap = Camera_Capture(matching_devices[preferred_idx]['uid'], timebase)
        logger.info("Camera selected: %s  with id: %s" %
                    (matching_devices[preferred_idx]['name'],
                     matching_devices[preferred_idx]['uid']))
        return cap

    #looking for attached cameras that match cv_id
    elif src_type is int:
        try:
            cap = device_list()[i]
        except IndexError, e:
            logger.warning('Camera with id %s not found.' % src_type)
            return FakeCapture(timebase=timebase)
        else:
            return Camera_Capture(cap['uid'], size, fps, timebase)
Exemplo n.º 2
0
def autoCreateCapture(src,timestamps=None,timebase = None):
    preferred_idx = 0
    # checking src and handling all cases:
    src_type = type(src)

    if src_type is tuple:
        src,preferred_idx = src
        src_type = type(src)

    #looking for attached cameras that match the suggested names
    if src_type is list:
        matching_devices = []
        for device in device_list():
            if any([s in device['name'] for s in src]):
                matching_devices.append(device)

        if len(matching_devices) > preferred_idx:
            logger.info('Found %s as devices that match the src string pattern Using the %s match.'%([d['name'] for d in matching_devices],('first','second','third','fourth')[preferred_idx]) )
        else:
            if len(matching_devices) == 0:
                logger.error('No device found that matched %s'%src)
            else:
                logger.error('Not enough devices found that matched %s'%src)
            return FakeCapture(timebase=timebase)


        cap = Camera_Capture(matching_devices[preferred_idx]['uid'],timebase)
        logger.info("Camera selected: %s  with id: %s" %(matching_devices[preferred_idx]['name'],matching_devices[preferred_idx]['uid']))
        return cap

    #looking for attached cameras that match cv_id
    elif src_type is int:
        try:
            cap = device_list()[i]
        except IndexError, e:
            logger.warning('Camera with id %s not found.'%src_type)
            return FakeCapture(timebase=timebase)
        else:
            return Camera_Capture(cap['uid'],size,fps,timebase)
Exemplo n.º 3
0
def uid_from_name(pattern):
    # looking for attached cameras that match the suggested names
    # give precedence to camera that matches the first pattern in list.
    matching_devices = []
    attached_devices = device_list()
    for name_pattern in pattern:
        for device in attached_devices:
            if name_pattern in device['name']:
                if is_accessible(device['uid']):
                    return device['uid']
                else:
                    logger.warning("Camera '%s' matches the pattern but is already in use"%device['name'])
    logger.error('No accessible device found that matched %s'%pattern)
Exemplo n.º 4
0
def uid_from_name(pattern):
    # looking for attached cameras that match the suggested names
    # give precedence to camera that matches the first pattern in list.
    matching_devices = []
    attached_devices = device_list()
    for name_pattern in pattern:
        for device in attached_devices:
            if name_pattern in device['name']:
                if is_accessible(device['uid']):
                    return device['uid']
                else:
                    logger.warning(
                        "Camera '%s' matches the pattern but is already in use"
                        % device['name'])
    logger.error('No accessible device found that matched %s' % pattern)
Exemplo n.º 5
0
def autoCreateCapture(src, timestamps=None, timebase=None):
    '''
    src can be one of the following:
     - a path to video file
     - patter of name matches
     - a device index
     - None
    '''
    # video source
    if type(src) is str and os.path.isfile(src):
        return File_Capture(src, timestamps=timestamps)

    # live src - select form idx
    if type(src) == int:
        try:
            uid = device_list()[src]['uid']
        except IndexError:
            logger.warning("UVC Camera at index:'%s' not found." % src)
            src = None
        else:
            if is_accessible(uid):
                logger.info("UVC Camera with id:'%s' selected." % src)
                return Camera_Capture(uid, timebase=timebase)
            else:
                logger.warning(
                    "Camera selected by id matches is found but already in use"
                )
                src = None

    # live src - select form pattern
    elif type(src) in (list, tuple):
        src = uid_from_name(src)

    # fake capture
    if src is None:
        logger.warning("Starting with Fake_Capture.")

    return Camera_Capture(src, timebase=timebase)
Exemplo n.º 6
0
def autoCreateCapture(src,timestamps=None,timebase = None):
    '''
    src can be one of the following:
     - a path to video file
     - patter of name matches
     - a device index
     - None
    '''
    # video source
    if type(src) is str and os.path.isfile(src):
        return File_Capture(src,timestamps=timestamps)

    # live src - select form idx
    if type(src) == int:
        try:
            uid = device_list()[src]['uid']
        except IndexError:
            logger.warning("UVC Camera at index:'%s' not found."%src)
            src = None
        else:
            if is_accessible(uid):
                logger.info("UVC Camera with id:'%s' selected."%src)
                return Camera_Capture(uid,timebase=timebase)
            else:
                logger.warning("Camera selected by id matches is found but already in use")
                src = None

    # live src - select form pattern
    elif type(src) in (list,tuple):
        src = uid_from_name(src)

    # fake capture
    if src is None:
        logger.warning("Starting with Fake_Capture.")

    return Camera_Capture(src,timebase=timebase)