def change_stream_method(option=''): # DEBUG: why do I need the global Camera? global Camera # when not specify option, use the request if option is '': new_stream_method = request.args.get('stream_method', 'PiCamera') option = new_stream_method if option == 'OpenCV': print('Change the stream method to OpenCV') # only change the stream method if the current one is not right if Camera.stream_method == 'PiCamera': Camera.stop_stream() from camera_pi_cv import Camera Camera.stream_method = 'OpenCV' Camera.start_stream() time.sleep(0.1) elif option == 'PiCamera': print('Change the stream method to Picamera') # only change the stream method if the current one is not right if Camera.stream_method == 'OpenCV': Camera.stop_stream() from camera_pi import Camera Camera.stream_method = 'PiCamera' Camera.start_stream() time.sleep(0.1)
def settings_io(): ''' swap between opencv and picamera for streaming''' # set default value for the stream_method try: Camera.stream_method except AttributeError: Camera.stream_method = 'PiCamera' zoom_value = request.args.get('zoom_value', '') config_update = request.args.get('config_update', '') stop_flag = request.args.get('stop', '') if zoom_value is not '': # only change zoom when passing an arg Camera.change_zoom(zoom_value) if config_update == 'true': Camera.update_camera_setting() if stop_flag == 'true': Camera.stop_stream() with open('config_picamera.yaml') as config_file: config = yaml.load(config_file) default_LED_RGB = config['default_LED_RGB'] print(default_LED_RGB) settings = { 'stream_method': Camera.stream_method, 'available_arduino_boards': Arduinos.available_arduino_boards, 'default_LED_RGB': default_LED_RGB } return jsonify(settings)