Face mesh

class apps.expert.core.aggression.video_aggression.face_mesh.FaceMesh(static_image_mode: bool = False, max_num_faces: int = 1, refine_landmarks: bool = True, min_detection_confidence: float = 0.5, min_tracking_confidence: float = 0.5)[source]

Bases: object

MediaPipe Face Mesh implementation.

MediaPipe Face Mesh processes an RGB image and returns 478 face landmarks on each detected face.

Parameters:
  • static_image_mode (int, optional) – Whether to treat the input images as a batch of static and possibly unrelated images or a video stream. Defaults to False.

  • max_num_faces (int, optional) – Maximum number of faces to detect. Defaults to 1.

  • refine_landmarks (bool, optional) – Whether to further refine the landmark coordinates around the eyes, lips and output additional landmarks around the irises. Defaults to True.

  • min_detection_confidence (float, optional) – Minimum confidence value ([0.0, 1.0]) for face detection to be considered successful. Defaults to 0.5.

  • min_tracking_confidence (float, optional) – Minimum confidence value ([0.0, 1.0]) for the face landmarks to be considered tracked successfully. Defaults to 0.5.

Example

>>> import cv2
>>> face_mesh = FaceMesh(static_image_mode=True, max_num_faces=1)
>>> image = cv2.imread('test.jpg')
>>> face_array = face_mesh.detect(image)
detect(image: ndarray, normalize: bool = True) ndarray[source]
Parameters:
  • image (np.ndarray) – BGR image represented as numpy ndarray.

  • normalize (bool, optional) – Apply minimax normalization to facial landmarks.

apps.expert.core.aggression.video_aggression.face_mesh.preprocess_face_vector(face_vector: ndarray, head_indexes: ndarray = array([0, 7, 10, 13, 14, 17, 21, 33, 37, 39, 40, 46, 52, 53, 54, 55, 58, 61, 63, 65, 66, 67, 70, 78, 80, 81, 82, 84, 87, 88, 91, 93, 95, 103, 105, 107, 109, 127, 132, 133, 136, 144, 145, 146, 148, 149, 150, 152, 153, 154, 155, 157, 158, 159, 160, 161, 162, 163, 172, 173, 176, 178, 181, 185, 191, 234, 246, 249, 251, 263, 267, 269, 270, 276, 282, 283, 284, 285, 288, 291, 293, 295, 296, 297, 300, 308, 310, 311, 312, 314, 317, 318, 321, 323, 324, 332, 334, 336, 338, 356, 361, 362, 365, 373, 374, 375, 377, 378, 379, 380, 381, 382, 384, 385, 386, 387, 388, 389, 390, 397, 398, 400, 402, 405, 409, 415, 454, 466])) ndarray[source]

Face landmarks preprocessing for head rotation prediction.

Parameters:
  • face_vector (np.ndarray) – Face landmarks represented as numpy ndarray.

  • head_indexes (np.ndarray) – To determine angles of head rotation, landmarks of the face, eyes and lips are used. This allows to reduce size of the input vector.