Exemplo n.º 1
0
	def run(self, context: ProcessContext):
		"""
		This method polls the queue for new messages
		and takes care of the action firing mechanism.
		:param context: Process context
		"""
		message_queue = context.get_prop('message_queue')

		# iterate through messages in queuone
		with ThreadPoolExecutor(max_workers=4) as executor:
			while True:
				StreamController.LOGGER.info('Checking message queue')
				messages = []
				count = 0

				# fetch messages
				while not message_queue.empty() and count <= self.message_limit:
					messages.append(message_queue.get(block=False))
					count += 1

				# process messages
				alert, action_messages = self.decide_alert(messages)

				# alert
				if alert:
					executor.submit(self.action.fire, action_messages)

				time.sleep(self.polling_interval)
Exemplo n.º 2
0
    def run(self, context: ProcessContext):
        try:
            cam = cv2.VideoCapture(self.parameters['device'])
            if not cam.isOpened():
                CameraProducer.LOGGER.error('Cannot capture device: ' +
                                            str(self.parameters['device']))
                return

            unsuccessful_images = 0
            data_proxy = context.get_prop('shared_data_proxy')

            while not context.stop_event.is_set():
                ret_val, img = cam.read()
                if ret_val:
                    data_proxy.set_data(img)
                else:
                    unsuccessful_images += 1
                    CameraProducer.LOGGER.warning('Could not capture image')
                    # if too many errors happen we better kill this process
                    if unsuccessful_images == self.parameters[
                            'unsuccessful_limit']:
                        break

                cv2.waitKey(self.parameters['wait_key_interval'])
        finally:
            CameraProducer.LOGGER.debug('Stopping capturing images')
            cam.release()
Exemplo n.º 3
0
def show_image(context: ProcessContext):
    data_proxy = context.get_prop('shared_data_proxy')
    consumer = CameraConsumer(set_consumer_parameters())
    consumer_context = ConsumerContext(None, False)
    try:
        while not context.stop_event.is_set():
            consumer_context.data = data_proxy.get_data()
            consumer.run(consumer_context)
    finally:
        cv2.destroyAllWindows()
Exemplo n.º 4
0
    def run(self, context: ProcessContext):
        count = 1
        data_proxy = context.get_prop('shared_data_proxy')

        while not context.stop_event.is_set():
            TestProducer.LOGGER.debug('Producer Loop iteration')
            time.sleep(TestProducer.SLEEP_INTERVAL)
            data_proxy.set_data(str(count))
            count += 1
            if count == 15:
                break
        TestProducer.LOGGER.debug('Stopping')
Exemplo n.º 5
0
    def run(self, context: ProcessContext):
        r = sr.Recognizer()

        with sr.Microphone() as source:
            MicrophoneProducer.LOGGER.info('Microphone active')
            audio = r.listen(source)
        try:
            if audio:
                data_proxy = context.get_prop('shared_data_proxy')
                data_proxy.set_data(audio)
                audio = None

        except sr.UnknownValueError:
            print("Google Speech Recognition could not understand audio")
        except sr.RequestError as e:
            print(
                "Could not request results from Google Speech Recognition service; {0}"
                .format(e))