private processDetectionResults()

in source/client/src/liveness/nose/NoseChallengeProcessor.ts [118:167]


  private processDetectionResults(
    results: faceapi.WithFaceLandmarks<{ detection: faceapi.FaceDetection }, faceapi.FaceLandmarks68>[]
  ) {
    const dims = faceapi.matchDimensions(this.overlayCanvasElement, this.cameraVideoElement);
    const resizedResults = faceapi.resizeResults(results, dims);
    const stateManagerOutput: StateManagerOutput = this.stateManager.process(results);

    if (ConfigUtils.getConfigBooleanValue("DRAW_DETECTIONS")) {
      faceapi.draw.drawDetections(this.overlayCanvasElement, resizedResults);
      faceapi.draw.drawFaceLandmarks(this.overlayCanvasElement, resizedResults);
    }

    if (stateManagerOutput.drawOptions) {
      this.overlayCanvasDrawer.draw(stateManagerOutput.drawOptions);
    }

    if (stateManagerOutput.helpMessage !== this.lastHelpMessage) {
      LogUtils.debug(`help message change: from='${this.lastHelpMessage}' to='${stateManagerOutput.helpMessage}'`);
      this.helpMessageCallback(stateManagerOutput.helpMessage);
    }
    this.lastHelpMessage = stateManagerOutput.helpMessage;

    if (stateManagerOutput.helpAnimationNumber !== this.lastHelpAnimationNumber) {
      LogUtils.debug(
        `help animation change: from=${this.lastHelpAnimationNumber} to=${stateManagerOutput.helpAnimationNumber}`
      );
      this.helpAnimationCallback(stateManagerOutput.helpAnimationNumber);
    }
    this.lastHelpAnimationNumber = stateManagerOutput.helpAnimationNumber;

    if (stateManagerOutput.shouldSaveFrame) {
      LogUtils.debug("should save frame");
      this.uploadPromises.push(this.uploadFrame());
    }

    // if challenge completed locally
    if (stateManagerOutput.end) {
      const localSuccess = stateManagerOutput.success as boolean;
      LogUtils.info("local challenge result: %s", localSuccess);
      this.localEndCallback(localSuccess);
      Promise.all(this.uploadPromises).then(() => {
        this.uploadEndCallback();
      });
    }
    // if not completed, schedule next frame capture
    else {
      const delay = 1000 / parseInt(ConfigUtils.getConfig().MAX_FPS);
      setTimeout(() => this.process(), delay);
    }
  }