def _process_frame_info(self, conn, msg_data):
        """
        Description: process frame info message
        Input:
            conn: a socket connection
            msg_data: msg body, serialized by protobuf
        Returns: True or False
        """
        request = pb2.FrameInfo()
        response = pb2.CommonResponse()
        msg_name = pb2._COMMONRESPONSE.full_name
        if not self._parse_protobuf(request, msg_data):
            return False

        sock_fileno = conn.fileno()
        handler = self.channel_manager.get_channel_handler_by_fd(sock_fileno)
        if handler is None:
            logging.error("get channel handler failed")
            response.ret = pb2.kErrorOther
            response.message = "channel error."
            self.send_message(conn, response, msg_name)
            return False

        face_list = self._recognize_face(request.feature)
        handler.save_frame(request.image, face_list)
        response.ret = pb2.kErrorNone
        response.message = "process frame info suceed."
        self.send_message(conn, response, msg_name)
        return True
예제 #2
0
def protobuf_image_request():
    send_request = facial_pb.FrameInfo()
    send_request.image = b'xxx'

    for i in range(1):
        face = send_request.feature.add()
        face.box.lt_x = 1
        face.box.lt_y = 1
        face.box.rb_x = 1
        face.box.rb_y = 1
        for j in range(1024):
            v = random.randint(0, 100)
            face.vector.append(v)

    return send_request.SerializeToString()