config.js 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. // config.js
  2. // Pure constants: landmark indices, calibration grid, parameters, connections.
  3. // No imports; no DOM access; no side effects.
  4. export const TRAIL_LENGTH = 30; // # of trail points
  5. export const ORB_RADIUS = 40; // px
  6. export const GRID_DRAW_INTERVAL_MS = 33; // ~30fps redraw
  7. // Kalman filter (replaces EMA + outlier threshold — Kalman handles noise naturally via R)
  8. // No constant needed here; see kalUpdate / kalInit below.
  9. // Calibration config
  10. export const CAL_SAMPLES_PER_POINT = 30; // samples per point (first 3 are discarded)
  11. export const CAL_SAMPLE_INTERVAL_MS = 50; // ms between samples
  12. export const CAL_MARGIN = 0.15; // 15% margin on each edge
  13. export const CAL_STORAGE_KEY = 'eye-tracking-calibration';
  14. // Bumped to 4: regression now uses 9-dim features (rX, rY, ear, pitch, yaw, rX², rY², rX*rY).
  15. // Old 6-coef payloads are rejected by loadCalibration() so the user re-calibrates once.
  16. export const CAL_VERSION = 4;
  17. // ---- Eye-state features (V2 model) ----
  18. // EAR (Eye Aspect Ratio) thresholds.
  19. // EAR = vertical eye-opening / horizontal eye-width.
  20. // An open eye is typically ~0.28–0.35; a fully closed eye is ~0.0.
  21. // A blink is a transient dip below ~0.22 (Soukupová & Čech, 2016).
  22. export const EAR_BLINK_THRESHOLD = 0.22; // < this value => blink frame; skip raw gaze update
  23. export const EAR_CLOSED_THRESHOLD = 0.15; // < this value => considered "eye closed"
  24. // ---- Head-pose feature switch ----
  25. // When true, the regression model includes simple geometric head-pitch / head-yaw
  26. // estimates (derived from nose vs. eye-corners / chin / forehead). The 9-dim
  27. // model below already wires them in; this flag is a documentation/extension
  28. // hook so we can later add features (e.g. roll) or fall back to 6-dim if needed.
  29. export const HEAD_POSE_FEATURES = true;
  30. // ---- Head-pose landmark indices (MediaPipe Face Mesh) ----
  31. // We use a simple geometric estimate (not full PnP). See computeHeadPose() in gaze.js.
  32. export const NOSE_TIP = 1; // tip of the nose
  33. export const CHIN = 152; // bottom of the chin
  34. export const FOREHEAD = 10; // top of the forehead (between brows)
  35. export const LEFT_EYE_CORNER = 33; // outer corner of the left eye (in raw frame)
  36. export const RIGHT_EYE_CORNER = 263; // outer corner of the right eye (in raw frame)
  37. // Iris / eye landmark indices (MediaPipe Face Mesh)
  38. // Left eye
  39. export const L_OUTER = 33, L_INNER = 133;
  40. export const L_TOP = 159, L_BOT = 145;
  41. export const L_IRIS = 468;
  42. // Right eye
  43. export const R_OUTER = 362, R_INNER = 263;
  44. export const R_TOP = 386, R_BOT = 374;
  45. export const R_IRIS = 473;
  46. // Iris contour points
  47. export const IRIS_LANDMARKS = [
  48. 468, 469, 470, 471, 472, // left iris
  49. 473, 474, 475, 476, 477 // right iris
  50. ];
  51. // Face mesh tesselation connection subsets (subset of FACE_TESSELATION)
  52. // Use eye / brow / lip / nose silhouettes to keep it light
  53. export const FACE_OVAL = [10, 338, 297, 332, 284, 251, 389, 356, 454, 323, 361, 288, 397, 365, 379, 378, 400, 377, 152, 148, 176, 149, 150, 136, 172, 58, 132, 93, 234, 127, 162, 21, 54, 103, 67, 109];
  54. export const LIPS = [61, 146, 91, 181, 84, 17, 314, 405, 321, 375, 291, 308, 324, 318, 402, 317, 14, 87, 178, 88, 95, 78];
  55. export const L_EYE = [33, 7, 163, 144, 145, 153, 154, 155, 133, 173, 157, 158, 159, 160, 161, 246];
  56. export const R_EYE = [362, 382, 381, 380, 374, 373, 390, 249, 263, 466, 388, 387, 386, 385, 384, 398];
  57. export const L_BROW = [46, 53, 52, 65, 55, 107, 66, 105, 63, 70];
  58. export const R_BROW = [276, 283, 282, 295, 285, 336, 296, 334, 293, 300];
  59. // 13-point calibration grid (center + 4 corners + 4 edges + 4 mid-diagonal)
  60. // The drawing is mirrored via CSS scaleX(-1), so these coords are
  61. // intentionally in the *displayed* (mirrored) frame of reference.
  62. // 5 rows × variable cols (5+3 cols) — center column used in rows 0,2,4 only.
  63. export const CAL_GRID = [
  64. // row 0 (top)
  65. { x: 0.1, y: 0.1 }, // TL
  66. { x: 0.5, y: 0.1 }, // TM
  67. { x: 0.9, y: 0.1 }, // TR
  68. // row 1 (upper mid)
  69. { x: 0.1, y: 0.3 }, // UL-mid
  70. { x: 0.9, y: 0.3 }, // UR-mid
  71. // row 2 (middle)
  72. { x: 0.1, y: 0.5 }, // ML
  73. { x: 0.5, y: 0.5 }, // MM (center)
  74. { x: 0.9, y: 0.5 }, // MR
  75. // row 3 (lower mid)
  76. { x: 0.1, y: 0.7 }, // LL-mid
  77. { x: 0.9, y: 0.7 }, // LR-mid
  78. // row 4 (bottom)
  79. { x: 0.1, y: 0.9 }, // BL
  80. { x: 0.5, y: 0.9 }, // BM
  81. { x: 0.9, y: 0.9 } // BR
  82. ];
  83. // Order: row-major traversal
  84. export const CAL_ORDER = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12];