File size: 1,340 Bytes
790e2c2
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
a56564c
790e2c2
 
 
 
 
 
 
 
 
 
 
 
a56564c
790e2c2
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
import os
import sys

import numpy as np

PROJECT_ROOT = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
if PROJECT_ROOT not in sys.path:
    sys.path.insert(0, PROJECT_ROOT)

from ui.pipeline import FaceMeshPipeline


class _DummyDetector:
    def __init__(self, landmarks=None):
        self._landmarks = landmarks

    def process(self, bgr_frame):
        return self._landmarks

    def close(self):
        return None


def test_face_mesh_pipeline_no_face_returns_expected_keys():
    pipe = FaceMeshPipeline(detector=_DummyDetector(landmarks=None))
    frame = np.zeros((480, 640, 3), dtype=np.uint8)
    out = pipe.process_frame(frame)

    assert isinstance(out, dict)
    for k in ("landmarks", "s_face", "s_eye", "raw_score", "is_focused", "yaw", "pitch", "roll", "mar", "is_yawning"):
        assert k in out
    assert out["landmarks"] is None
    assert 0.0 <= float(out["raw_score"]) <= 1.0


def test_face_mesh_pipeline_with_fake_landmarks_runs():
    fake_lm = np.zeros((478, 2), dtype=np.float32)
    pipe = FaceMeshPipeline(detector=_DummyDetector(landmarks=fake_lm))
    frame = np.zeros((480, 640, 3), dtype=np.uint8)
    out = pipe.process_frame(frame)

    assert out["landmarks"] is not None
    assert "is_focused" in out
    assert "raw_score" in out
    assert 0.0 <= float(out["raw_score"]) <= 1.0