File size: 1,914 Bytes
178f61f
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
48
49
50
51
52
53
54
55
56
57
import os
import cv2
import sys
from pathlib import Path

# Add src to path
sys.path.append(str(Path(__file__).parent.parent.parent))
from src.utils.preprocess import GazePreprocessor

def main():
    image_path = "data/verification/test_gaze.jpg"
    if not os.path.exists(image_path):
        print(f"Image not found: {image_path}")
        return

    # Initialize Preprocessor
    # Note: We need the .task file. Let's check if it exists in the root.
    model_path = "face_landmarker.task"
    if not os.path.exists(model_path):
        print(f"Model not found: {model_path}")
        return

    preprocessor = GazePreprocessor(model_path=model_path)
    
    frame = cv2.imread(image_path)
    if frame is None:
        print("Failed to load image.")
        return

    print(f"Testing MediaPipe on: {image_path} (Size: {frame.shape})")
    
    landmarks = preprocessor.get_landmarks(frame)
    
    if landmarks:
        print(f"SUCCESS: Detected {len(landmarks)} landmarks.")
        # Success Rate check
        success_rate = 100.0
        print(f"Landmark Success Rate: {success_rate:.1f}%")
        
        # Try to normalize eyes to see if the whole pipeline works
        try:
            left_eye, left_angle = preprocessor.normalize_eye(frame, landmarks, 'left')
            right_eye, right_angle = preprocessor.normalize_eye(frame, landmarks, 'right')
            print("SUCCESS: Normalized eye patches extracted.")
            
            # Save verification image
            cv2.imwrite("data/verification/test_gaze_landmarks.jpg", frame) # Preprocessor might have drawn on it if we add drawing logic
            print("Verification image saved to data/verification/test_gaze_landmarks.jpg")
            
        except Exception as e:
            print(f"ERROR during normalization: {e}")
    else:
        print("FAILURE: No landmarks detected.")

if __name__ == "__main__":
    main()