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

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

        if len(matching_devices) > 1:
            logger.warning(
                'Found %s as devices that match the src string pattern Using the first one.'
                % [d.name for d in matching_devices])
        if len(matching_devices) == 0:
            logger.error('No device found that matched %s' % src)
            return FakeCapture(size, fps, timebase=timebase)

        cap = Camera_Capture(matching_devices[0],
                             filter_sizes(matching_devices[0], size), fps,
                             timebase)
        logger.info("Camera selected: %s  with id: %s" %
                    (cap.name, cap.src_id))
        return cap

    #looking for attached cameras that match cv_id
    elif src_type is int:
        for device in Camera_List():
            if device.src_id == src:
                cap = Camera_Capture(device, filter_sizes(device, size), fps,
                                     timebase)
                logger.info("Camera selected: %s  with id: %s" %
                            (cap.name, cap.src_id))
                return cap

        #control not supported for windows: init capture without uvc controls
        cap = Camera_Capture(src, size, fps, timebase)
        logger.warning('No UVC support: Using camera with id: %s' % src)
        return cap

    #looking for videofiles
    elif src_type is str:
        if not isfile(src):
            logger.error('Could not locate VideoFile %s' % src)
            raise FileCaptureError('Could not locate VideoFile %s' % src)
        logger.info("Using %s as video source" % src)
        return File_Capture(src, timestamps=timestamps)
    else:
        logger.error(
            "autoCreateCapture: Could not create capture, wrong src_type")
        return FakeCapture(size, fps, timebase=timebase)
Exemplo n.º 2
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.º 3
0
                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)

    #looking for videofiles
    elif src_type is str:
        if not isfile(src):
            logger.error('Could not locate VideoFile %s' % src)
            raise FileCaptureError('Could not locate VideoFile %s' % src)
        logger.info("Using %s as video source" % src)
        return File_Capture(src, timestamps=timestamps)
    else:
        logger.error(
            "autoCreateCapture: Could not create capture, wrong src_type")
        return FakeCapture(size, fps, timebase=timebase)