main.py
// ===============================
// EyeOS – Main Entry Point
// ===============================
import cv2
import os
from mediapipe.tasks.python import vision
from mediapipe.tasks.python import BaseOptions
from mediapipe import Image, ImageFormat
from eye_mouse import move_mouse
# ---------- PATH SETUP ----------
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
MODEL_PATH = os.path.join(BASE_DIR, "face_landmarker.task")
# ---------- MEDIAPIPE OPTIONS ----------
face_options = vision.FaceLandmarkerOptions(
base_options=BaseOptions(model_asset_path=MODEL_PATH),
running_mode=vision.RunningMode.VIDEO,
num_faces=1
)
landmarker = vision.FaceLandmarker.create_from_options(face_options)
# ---------- CAMERA ----------
cap = cv2.VideoCapture(0)
frame_id = 0
LEFT_EYE_OUT = 33
LEFT_EYE_IN = 133
# ---------- LOOP ----------
while True:
ret, frame = cap.read()
if not ret:
break
frame_id += 1
h, w, _ = frame.shape
rgb = cv2.cvtColor(frame, cv2.COLOR_BGR2RGB)
mp_img = Image(image_format=ImageFormat.SRGB, data=rgb)
result = landmarker.detect_for_video(mp_img, frame_id)
if result.face_landmarks:
face = result.face_landmarks[0]
p_out = face[LEFT_EYE_OUT]
p_in = face[LEFT_EYE_IN]
eye_x = (p_out.x + p_in.x) / 2
eye_y = (p_out.y + p_in.y) / 2
cx = int(eye_x * w)
cy = int(eye_y * h)
cv2.circle(frame, (cx, cy), 4, (0, 255, 0), -1)
move_mouse(eye_x, eye_y)
cv2.imshow("Eye → Mouse Control", frame)
if cv2.waitKey(1) & 0xFF == 27:
break
cap.release()
cv2.destroyAllWindows()