frame size specification for video sources in video.py

pull/13383/head
Alexander Mordvintsev 14 years ago
parent 823b6567a3
commit 39268013d5
  1. 35
      samples/python2/video.py

@ -101,25 +101,32 @@ presets = dict(
def create_capture(source = 0, fallback = presets['chess']):
'''
source: <int> or '<int>' or '<filename>' or 'synth:<params>'
source: <int> or '<int>|<filename>|synth [:<param_name>=<value> [:...]]'
'''
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)

Loading…
Cancel
Save