def verify_challenge()

in lambda/states/nose.py [0:0]


    def verify_challenge(self, current_landmarks, pose, challenge_in_the_right):
        # Validating continuous and linear nose trajectory
        nose_trajectory_x = [nose[0] for nose in self.nose_trajectory]
        nose_trajectory_y = [nose[1] for nose in self.nose_trajectory]
        _, residuals, _, _, _ = np.polyfit(nose_trajectory_x, nose_trajectory_y, 2, full=True)
        trajectory_error = math.sqrt(residuals/len(self.nose_trajectory))
        if trajectory_error > NoseState.TRAJECTORY_ERROR_THRESHOLD:
            return False

        # Plotting landmarks from the first frame in a histogram
        original_landmarks_x = [self.image_width * landmark['X'] for landmark in self.original_landmarks]
        original_landmarks_y = [self.image_height * landmark['Y'] for landmark in self.original_landmarks]
        original_histogram, _, _ = np.histogram2d(original_landmarks_x,
                                                  original_landmarks_y,
                                                  bins=NoseState.HISTOGRAM_BINS)
        original_histogram = np.reshape(original_histogram, NoseState.HISTOGRAM_BINS**2) / len(original_landmarks_x)
        # Plotting landmarks from the last frame in a histogram
        current_landmarks_x = [self.image_width * landmark['X'] for landmark in current_landmarks]
        current_landmarks_y = [self.image_height * landmark['Y'] for landmark in current_landmarks]
        current_histogram, _, _ = np.histogram2d(current_landmarks_x,
                                                 current_landmarks_y,
                                                 bins=NoseState.HISTOGRAM_BINS)
        current_histogram = np.reshape(current_histogram, NoseState.HISTOGRAM_BINS**2) / len(current_landmarks_x)
        # Calculating the Euclidean distance between histograms
        dist = np.linalg.norm(original_histogram - current_histogram)
        # Estimating left and right rotation
        yaw = pose['Yaw']
        rotated_right = yaw > NoseState.ROTATION_THRESHOLD
        rotated_left = yaw < - NoseState.ROTATION_THRESHOLD
        rotated_face = rotated_left or rotated_right
        # Validating distance according to rotation
        if (rotated_right and challenge_in_the_right) or (rotated_left and not challenge_in_the_right):
            min_dist = NoseState.MIN_DIST * NoseState.MIN_DIST_FACTOR_ROTATED
        elif not rotated_face:
            min_dist = NoseState.MIN_DIST * NoseState.MIN_DIST_FACTOR_NOT_ROTATED
        else:
            return False

        if dist > min_dist:
            return True
        return False