Requirements:
python >= 3.12
,numpy >= 1.21
.
- Install the package with a following command:
python3 -m pip install mini-face
- Download model data files (
model
andAU_predictors
) from this repository or official OpenFace release. You will also need files from OpenFace models.
To estimate gaze on a single image, simply run:
from pathlib import Path
import cv2
import numpy as np
from mini_face import gaze, PredictionMode
if __name__ == "__main__":
extractor = gaze.Extractor(
mode=PredictionMode.IMAGE, # Specify prediction mode
focal_length=(500.0, 500.0), # Specify camera parameters
optical_center=(860.0, 540.0), # required for proper 3D estimation
models_directory=Path("./model"), # Pass a directory to search for OpenFace weights in
)
image = cv2.imread("test_image.jpg")
result = extractor.predict(
image, # Pass the image to analyze
np.array([0, 0, 1080, 1920]) # along with a region to search for face in
)
print(f"{result = }")