diff --git a/samples/python2/video.py b/samples/python2/video.py index 80e1282b79..d03cdbd81c 100644 --- a/samples/python2/video.py +++ b/samples/python2/video.py @@ -101,25 +101,32 @@ presets = dict( def create_capture(source = 0, fallback = presets['chess']): ''' - source: or '' or '' or 'synth:' + source: or '||synth [:= [:...]]' ''' - cap = None + source = str(source).strip() + chunks = source.split(':') + # hanlde drive letter ('c:', ...) + if len(chunks) > 1 and len(chunks[0]) == 1 and chunks[0].isalpha(): + chunks[1] = chunks[0] + ':' + chunks[1] + del chunks[0] + + source = chunks[0] try: source = int(source) except ValueError: pass + params = dict( s.split('=') for s in chunks[1:] ) + + cap = None + if source == 'synth': + Class = classes.get(params.get('class', None), VideoSynthBase) + try: cap = Class(**params) + except: pass else: cap = cv2.VideoCapture(source) - if cap is None: - source = str(source).strip() - if source.startswith('synth'): - ss = filter(None, source.split(':')) - params = dict( s.split('=') for s in ss[1:] ) - try: Class = classes[params['class']] - except: Class = VideoSynthBase - try: cap = Class(**params) - except: pass - if cap is None: - cap = cv2.VideoCapture(source) - if not cap.isOpened(): + if 'size' in params: + w, h = map(int, params['size'].split('x')) + cap.set(cv2.cv.CV_CAP_PROP_FRAME_WIDTH, w) + cap.set(cv2.cv.CV_CAP_PROP_FRAME_HEIGHT, h) + if cap is None or not cap.isOpened(): print 'Warning: unable to open video source: ', source if fallback is not None: return create_capture(fallback, None)