def _process_face_result(self, conn, msg_data): """ Description: process face_result message Input: msg_data: msg body, serialized by protobuf Returns: True or False """ face_result = pb2.FaceResult() if not self._parse_protobuf(face_result, msg_data): return False face_id = face_result.id if not self.register_dict.get(face_id): logging.warning("face id %s is already deleted", face_id) self._send_common_respone(conn, pb2.kErrorNone, "face id is already deleted") return True ret = face_result.response.ret if ret != pb2.kErrorNone: err_msg = face_result.response.message logging.error("get face feature error message: %s", err_msg) status = FACE_REGISTER_STATUS_FAILED message = "Get face feature failed" self._update_register_dict(face_id, status, message) self._send_common_respone(conn, pb2.kErrorOther, message) return True face_num = len(face_result.feature) if face_num == 0: status = FACE_REGISTER_STATUS_FAILED message = "No face recognized" self._update_register_dict(face_id, status, message) ret = False elif face_num > 1: status = FACE_REGISTER_STATUS_FAILED message = "{} faces recognized".format(face_num) self._update_register_dict(face_id, status, message) ret = False else: box = face_result.feature[0].box face_coordinate = [box.lt_x, box.lt_y, box.rb_x, box.rb_x] feature_vector = [i for i in face_result.feature[0].vector] if len(feature_vector) != FEATURE_VECTOR_LENGTH: logging.error("feature_vector length not equal 1024") status = FACE_REGISTER_STATUS_FAILED message = "Face feature vector length invalid" self._update_register_dict(face_id, status, message) ret = True else: ret, message = self._save_face_feature(face_id, face_coordinate, feature_vector) error_code = pb2.kErrorNone if (ret == True) else pb2.kErrorOther self._send_common_respone(conn, error_code, message) return ret
def face_feature(face_id): response = facial_pb.FaceResult() response.id = face_id response.response.ret = facial_pb.kErrorNone response.response.message = "succeed" for i in range(1): face = response.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): face.vector.append(100) return response.SerializeToString()