mirror of
https://github.com/ck-zhang/EyePy.git
synced 2025-12-30 15:49:48 -06:00
Refactor CLI argument parsing into cli.py
This commit is contained in:
@@ -1,9 +1,7 @@
|
||||
import time
|
||||
import cv2
|
||||
import numpy as np
|
||||
import argparse
|
||||
import os
|
||||
|
||||
from eyetrax.utils.screen import get_screen_size
|
||||
from eyetrax.gaze import GazeEstimator
|
||||
from eyetrax.calibration import (
|
||||
@@ -18,21 +16,12 @@ from eyetrax.filters import (
|
||||
KDESmoother,
|
||||
NoSmoother,
|
||||
)
|
||||
from eyetrax.cli import parse_common_args
|
||||
|
||||
|
||||
def run_demo():
|
||||
parser = argparse.ArgumentParser(
|
||||
description="Gaze Estimation with Kalman Filter or KDE"
|
||||
)
|
||||
parser.add_argument("--filter", choices=["kalman", "kde", "none"], default="none")
|
||||
parser.add_argument("--camera", type=int, default=0)
|
||||
parser.add_argument(
|
||||
"--calibration", choices=["9p", "5p", "lissajous"], default="9p"
|
||||
)
|
||||
parser.add_argument("--background", type=str, default=None)
|
||||
parser.add_argument("--confidence", type=float, default=0.5, help="0 < value < 1")
|
||||
parser.add_argument("--model", default="ridge", help="Registered model to use")
|
||||
args = parser.parse_args()
|
||||
|
||||
args = parse_common_args()
|
||||
|
||||
filter_method = args.filter
|
||||
camera_index = args.camera
|
||||
|
||||
@@ -3,7 +3,6 @@ import time
|
||||
import cv2
|
||||
import numpy as np
|
||||
import pyvirtualcam
|
||||
|
||||
from eyetrax.utils.screen import get_screen_size
|
||||
from eyetrax.gaze import GazeEstimator
|
||||
from eyetrax.calibration import (
|
||||
@@ -18,17 +17,12 @@ from eyetrax.filters import (
|
||||
KDESmoother,
|
||||
NoSmoother,
|
||||
)
|
||||
from eyetrax.cli import parse_common_args
|
||||
|
||||
|
||||
def run_virtualcam():
|
||||
parser = argparse.ArgumentParser(description="Virtual Camera Gaze Overlay")
|
||||
parser.add_argument("--filter", choices=["kalman", "kde", "none"], default="none")
|
||||
parser.add_argument("--camera", type=int, default=0)
|
||||
parser.add_argument(
|
||||
"--calibration", choices=["9p", "5p", "lissajous"], default="9p"
|
||||
)
|
||||
parser.add_argument("--confidence", type=float, default=0.5)
|
||||
args = parser.parse_args()
|
||||
|
||||
args = parse_common_args()
|
||||
|
||||
filter_method = args.filter
|
||||
camera_index = args.camera
|
||||
@@ -36,6 +30,7 @@ def run_virtualcam():
|
||||
confidence_level = args.confidence
|
||||
|
||||
gaze_estimator = GazeEstimator()
|
||||
|
||||
if calibration_method == "9p":
|
||||
run_9_point_calibration(gaze_estimator, camera_index=camera_index)
|
||||
elif calibration_method == "5p":
|
||||
|
||||
44
src/eyetrax/cli.py
Normal file
44
src/eyetrax/cli.py
Normal file
@@ -0,0 +1,44 @@
|
||||
import argparse
|
||||
|
||||
|
||||
def parse_common_args():
|
||||
|
||||
parser = argparse.ArgumentParser(description="Common Gaze Estimation Arguments")
|
||||
|
||||
parser.add_argument(
|
||||
"--filter",
|
||||
choices=["kalman", "kde", "none"],
|
||||
default="none",
|
||||
help="Select the filter to apply to gaze estimation, options are 'kalman', 'kde', or 'none'",
|
||||
)
|
||||
parser.add_argument(
|
||||
"--camera",
|
||||
type=int,
|
||||
default=0,
|
||||
help="Camera index for video capture, default is 0 (first camera)",
|
||||
)
|
||||
parser.add_argument(
|
||||
"--calibration",
|
||||
choices=["9p", "5p", "lissajous"],
|
||||
default="9p",
|
||||
help="Calibration method for gaze estimation, options are '9p', '5p', or 'lissajous'",
|
||||
)
|
||||
parser.add_argument(
|
||||
"--background",
|
||||
type=str,
|
||||
default=None,
|
||||
help="Path to a custom background image (optional)",
|
||||
)
|
||||
parser.add_argument(
|
||||
"--confidence",
|
||||
type=float,
|
||||
default=0.5,
|
||||
help="Confidence level for KDE smoothing, range 0 to 1",
|
||||
)
|
||||
parser.add_argument(
|
||||
"--model",
|
||||
default="ridge",
|
||||
help="The machine learning model to use for gaze estimation, default is 'ridge'",
|
||||
)
|
||||
|
||||
return parser.parse_args()
|
||||
Reference in New Issue
Block a user