frame size specification for video sources in video.py
This commit is contained in:
parent
823b6567a3
commit
39268013d5
@ -101,25 +101,32 @@ presets = dict(
|
|||||||
|
|
||||||
def create_capture(source = 0, fallback = presets['chess']):
|
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)
|
try: source = int(source)
|
||||||
except ValueError: pass
|
except ValueError: pass
|
||||||
else:
|
params = dict( s.split('=') for s in chunks[1:] )
|
||||||
cap = cv2.VideoCapture(source)
|
|
||||||
if cap is None:
|
cap = None
|
||||||
source = str(source).strip()
|
if source == 'synth':
|
||||||
if source.startswith('synth'):
|
Class = classes.get(params.get('class', None), VideoSynthBase)
|
||||||
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)
|
try: cap = Class(**params)
|
||||||
except: pass
|
except: pass
|
||||||
if cap is None:
|
else:
|
||||||
cap = cv2.VideoCapture(source)
|
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
|
print 'Warning: unable to open video source: ', source
|
||||||
if fallback is not None:
|
if fallback is not None:
|
||||||
return create_capture(fallback, None)
|
return create_capture(fallback, None)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user