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)
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)
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)