Exemple #1
0
def _run_engine(engine_factory, conn):
    engine = engine_factory()
    logger.info('Cognitive engine started')
    while True:
        input_frame = gabriel_pb2.InputFrame()
        input_frame.ParseFromString(conn.recv_bytes())

        result_wrapper = engine.handle(input_frame)
        conn.send_bytes(result_wrapper.SerializeToString())
Exemple #2
0
        async def producer():
            _, frame = capture.read()
            cv2.putText(frame, text, ORG, FONT_FACE, FONT_SCALE, COLOR)
            _, jpeg_frame=cv2.imencode('.jpg', frame)
            input_frame = gabriel_pb2.InputFrame()
            input_frame.payload_type = gabriel_pb2.PayloadType.IMAGE
            input_frame.payloads.append(jpeg_frame.tobytes())

            return input_frame
Exemple #3
0
def send_frames(source):
    capture = cv2.VideoCapture(0)
    while True:
        _, frame = capture.read()
        _, jpeg_frame = cv2.imencode('.jpg', frame)
        input_frame = gabriel_pb2.InputFrame()
        input_frame.payload_type = gabriel_pb2.PayloadType.IMAGE
        input_frame.payloads.append(jpeg_frame.tobytes())

        source.send(input_frame)
        time.sleep(0.1)
Exemple #4
0
        async def producer():
            _, frame = self._video_capture.read()
            if frame is None:
                return None

            frame = self._preprocess(frame)
            _, jpeg_frame = cv2.imencode('.jpg', frame)

            input_frame = gabriel_pb2.InputFrame()
            input_frame.payload_type = gabriel_pb2.PayloadType.IMAGE
            input_frame.payloads.append(jpeg_frame.tobytes())

            extras = self._produce_extras()
            if extras is not None:
                input_frame.extras.Pack(extras)

            return input_frame
Exemple #5
0
def run(engine,
        source_name,
        server_address,
        all_responses_required=False,
        timeout=TEN_SECONDS,
        request_retries=REQUEST_RETRIES):
    context = zmq.Context()

    while request_retries > 0:
        socket = context.socket(zmq.REQ)
        socket.connect(server_address)
        from_standalone_engine = gabriel_pb2.FromStandaloneEngine()
        from_standalone_engine.welcome.source_name = source_name
        from_standalone_engine.welcome.all_responses_required = (
            all_responses_required)
        socket.send(from_standalone_engine.SerializeToString())
        logger.info('Sent welcome message to server')

        while True:
            if socket.poll(timeout) == 0:
                logger.warning('No response from server')
                socket.setsockopt(zmq.LINGER, 0)
                socket.close()
                request_retries -= 1
                break

            message_from_server = socket.recv()
            if message_from_server == network_engine.HEARTBEAT:
                socket.send(network_engine.HEARTBEAT)
                continue

            input_frame = gabriel_pb2.InputFrame()
            input_frame.ParseFromString(message_from_server)
            result_wrapper = engine.handle(input_frame)

            from_standalone_engine = gabriel_pb2.FromStandaloneEngine()
            from_standalone_engine.result_wrapper.CopyFrom(result_wrapper)
            socket.send(from_standalone_engine.SerializeToString())

    logger.warning('Ran out of retires. Abandoning server connection.')
Exemple #6
0
        async def producer():
            frame = self.recv_array()

            if frame is None:
                return None

            frame = self._preprocess(frame)
            if self.display_frames:
                cv2.imshow("Frames sent to ZmqAdapter", frame)
                cv2.waitKey(1)

            _, jpeg_frame = cv2.imencode('.jpg', frame)

            input_frame = gabriel_pb2.InputFrame()
            input_frame.payload_type = gabriel_pb2.PayloadType.IMAGE
            input_frame.payloads.append(jpeg_frame.tobytes())

            extras = self.produce_extras()
            if extras is not None:
                input_frame.extras.Pack(extras)

            logger.debug(f"Sending frame {self.frames_processed}...")
            return input_frame
Exemple #7
0
 def reader_callback():
     input_frame = gabriel_pb2.InputFrame()
     input_frame.ParseFromString(self._read.recv_bytes())
     self._latest_input_frame = input_frame
     self._frame_available.set()
Exemple #8
0
    async def producer():

        # Do not use time.sleep. This would stop the event loop.
        await asyncio.sleep(1)

        return gabriel_pb2.InputFrame()