Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
if "-fps" not in self.output_parameters:
FPS = 25
#auto assign dimensions
HEIGHT = self.inputheight
WIDTH = self.inputwidth
#assign parameter dict values to variables
try:
for key, value in self.output_parameters.items():
if key == '-fourcc':
FOURCC = cv2.VideoWriter_fourcc(*(value.upper()))
elif key == '-fps':
FPS = float(value)
elif key =='-backend' and value.upper() in ['CAP_FFMPEG','CAP_GSTREAMER']:
BACKEND = capPropId(value.upper())
elif key == '-color':
COLOR = bool(int(value))
else:
pass
except Exception as e:
# log if something is wrong
if self.logging:
print(e)
raise ValueError('Wrong Values passed to OpenCV Writer, Kindly Refer Docs!')
if self.logging:
#log values for debugging
print('FILE_PATH: {}, FOURCC = {}, FPS = {}, WIDTH = {}, HEIGHT = {}, BACKEND = {}'.format(self.out_file,FOURCC, FPS, WIDTH, HEIGHT, BACKEND))
#start different process for with/without Backend.
#log it
if logging:
print('Enabling Threaded Queue Mode!')
else:
#otherwise disable it
self.threaded_queue_mode = False
#intiate screen dimension handler
screen_dims = {}
#initializing colorspace variable
self.color_space = None
try:
#reformat proper mss dict and assign to screen dimension handler
screen_dims = {k.strip(): v for k,v in options.items() if k.strip() in ["top", "left", "width", "height"]}
# separately handle colorspace value to int conversion
if not(colorspace is None):
self.color_space = capPropId(colorspace.strip())
except Exception as e:
# Catch if any error occurred
if logging:
print(e)
# intialize mss capture instance
self.mss_capture_instance = None
try:
# check whether user-defined dimensions are provided
if screen_dims and len(screen_dims) == 4:
self.mss_capture_instance = screen_dims #create instance from dimensions
else:
self.mss_capture_instance = monitor_instance #otherwise create instance from monitor
# extract global frame from instance
self.frame = np.asanyarray(self.mss_object.grab(self.mss_capture_instance))
if self.threaded_queue_mode:
#intitialize and append to queue
# Two parameters are available since OpenCV 4+ (master branch)
self.stream = cv2.VideoCapture(source, backend)
else:
# initialize the camera stream
self.stream = cv2.VideoCapture(source)
#initializing colorspace variable
self.color_space = None
try:
# try to apply attributes to source if specified
#reformat dict
options = {k.strip(): v for k,v in options.items()}
for key, value in options.items():
self.stream.set(capPropId(key),value)
# separately handle colorspace value to int conversion
if not(colorspace is None):
self.color_space = capPropId(colorspace.strip())
except Exception as e:
# Catch if any error occurred
if logging:
print(e)
#initialize and assign framerate variable
self.framerate = 0
try:
_fps = self.stream.get(cv2.CAP_PROP_FPS)
if _fps>1:
self.framerate = _fps
self.framerate = framerate
#initializing colorspace variable
self.color_space = None
#reformat dict
options = {k.strip(): v for k,v in options.items()}
try:
# apply attributes to source if specified
for key, value in options.items():
setattr(self.camera, key, value)
# separately handle colorspace value to int conversion
if not(colorspace is None):
self.color_space = capPropId(colorspace.strip())
except Exception as e:
# Catch if any error occurred
if logging:
print(e)
# enable rgb capture array thread and capture stream
self.rawCapture = PiRGBArray(self.camera, size=resolution)
self.stream = self.camera.capture_continuous(self.rawCapture,format="bgr", use_video_port=True)
#frame variable initialization
for stream in self.stream:
self.frame = stream.array
self.rawCapture.seek(0)
self.rawCapture.truncate()
break
self.stream = cv2.VideoCapture(source)
#initializing colorspace variable
self.color_space = None
try:
# try to apply attributes to source if specified
#reformat dict
options = {k.strip(): v for k,v in options.items()}
for key, value in options.items():
self.stream.set(capPropId(key),value)
# separately handle colorspace value to int conversion
if not(colorspace is None):
self.color_space = capPropId(colorspace.strip())
except Exception as e:
# Catch if any error occurred
if logging:
print(e)
#initialize and assign framerate variable
self.framerate = 0
try:
_fps = self.stream.get(cv2.CAP_PROP_FPS)
if _fps>1:
self.framerate = _fps
except Exception as e:
if logging:
print(e)
self.framerate = 0