MCPcopy Index your code
hub / github.com/makelove/OpenCV-Python-Tutorial / create_capture

Function create_capture

官方samples/video.py:168–198  ·  view source on GitHub ↗

source: or ' | |synth [: = [:...]]'

(source = 0, fallback = presets['chess'])

Source from the content-addressed store, hash-verified

166
167
168def create_capture(source = 0, fallback = presets['chess']):
169 '''source: <int> or '<int>|<filename>|synth [:<param_name>=<value> [:...]]&#x27;
170 ''&#x27;
171 source = str(source).strip()
172 chunks = source.split(':')
173 # handle drive letter ('c:', ...)
174 if len(chunks) > 1 and len(chunks[0]) == 1 and chunks[0].isalpha():
175 chunks[1] = chunks[0] + ':' + chunks[1]
176 del chunks[0]
177
178 source = chunks[0]
179 try: source = int(source)
180 except ValueError: pass
181 params = dict( s.split('=') for s in chunks[1:] )
182
183 cap = None
184 if source == 'synth':
185 Class = classes.get(params.get('class', None), VideoSynthBase)
186 try: cap = Class(**params)
187 except: pass
188 else:
189 cap = cv2.VideoCapture(source)
190 if 'size' in params:
191 w, h = map(int, params['size'].split('x'))
192 cap.set(cv2.CAP_PROP_FRAME_WIDTH, w)
193 cap.set(cv2.CAP_PROP_FRAME_HEIGHT, h)
194 if cap is None or not cap.isOpened():
195 print('Warning: unable to open video source: ', source)
196 if fallback is not None:
197 return create_capture(fallback, None)
198 return cap
199
200if __name__ == '__main__':
201 import sys

Callers 1

facedetect.pyFile · 0.90

Calls 2

getMethod · 0.80
isOpenedMethod · 0.80

Tested by

no test coverage detected