caught-you-looking 0.1.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (26) hide show
  1. caught_you_looking-0.1.0/LICENSE +21 -0
  2. caught_you_looking-0.1.0/PKG-INFO +228 -0
  3. caught_you_looking-0.1.0/README.md +203 -0
  4. caught_you_looking-0.1.0/pyproject.toml +72 -0
  5. caught_you_looking-0.1.0/pyproject.toml.orig +60 -0
  6. caught_you_looking-0.1.0/src/caught_you_looking/__init__.py +2 -0
  7. caught_you_looking-0.1.0/src/caught_you_looking/calibration/__init__.py +0 -0
  8. caught_you_looking-0.1.0/src/caught_you_looking/calibration/calibration.py +59 -0
  9. caught_you_looking-0.1.0/src/caught_you_looking/calibration/persistence.py +29 -0
  10. caught_you_looking-0.1.0/src/caught_you_looking/calibration/profiles.py +65 -0
  11. caught_you_looking-0.1.0/src/caught_you_looking/cli.py +71 -0
  12. caught_you_looking-0.1.0/src/caught_you_looking/hyprland/__init__.py +0 -0
  13. caught_you_looking-0.1.0/src/caught_you_looking/hyprland/commands.py +32 -0
  14. caught_you_looking-0.1.0/src/caught_you_looking/hyprland/events.py +12 -0
  15. caught_you_looking-0.1.0/src/caught_you_looking/hyprland/listener.py +135 -0
  16. caught_you_looking-0.1.0/src/caught_you_looking/main.py +51 -0
  17. caught_you_looking-0.1.0/src/caught_you_looking/paths.py +28 -0
  18. caught_you_looking-0.1.0/src/caught_you_looking/tracking/__init__.py +0 -0
  19. caught_you_looking-0.1.0/src/caught_you_looking/tracking/runtime.py +44 -0
  20. caught_you_looking-0.1.0/src/caught_you_looking/tracking/tracker.py +74 -0
  21. caught_you_looking-0.1.0/src/caught_you_looking/tracking.py +0 -0
  22. caught_you_looking-0.1.0/src/caught_you_looking/vision/__init__.py +0 -0
  23. caught_you_looking-0.1.0/src/caught_you_looking/vision/camera.py +17 -0
  24. caught_you_looking-0.1.0/src/caught_you_looking/vision/detection.py +68 -0
  25. caught_you_looking-0.1.0/src/caught_you_looking/vision/headpose.py +43 -0
  26. caught_you_looking-0.1.0/src/caught_you_looking/vision/models.py +30 -0
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Samuel Freundel
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,228 @@
1
+ Metadata-Version: 2.4
2
+ Name: caught-you-looking
3
+ Version: 0.1.0
4
+ Summary: Automatic monitor focusing based on head orientation for Hyprland.
5
+ Keywords: hyprland,wayland,head-tracking,computer-vision
6
+ Author: Samuel Freundel
7
+ Author-email: Samuel Freundel <samuel.freundel@uni-ulm.de>
8
+ License-Expression: MIT
9
+ License-File: LICENSE
10
+ Classifier: Development Status :: 3 - Alpha
11
+ Classifier: Environment :: Console
12
+ Classifier: Operating System :: POSIX :: Linux
13
+ Classifier: Programming Language :: Python :: 3
14
+ Classifier: Programming Language :: Python :: 3.14
15
+ Classifier: Topic :: Desktop Environment
16
+ Requires-Dist: mediapipe>=1.2.3
17
+ Requires-Dist: numpy>=2.5.5
18
+ Requires-Dist: opencv-python>=5.1.0.95
19
+ Requires-Dist: scipy>=1.18.1
20
+ Requires-Python: >=3.14
21
+ Project-URL: Homepage, https://github.com/safreu/caught-you-looking
22
+ Project-URL: Repository, https://github.com/safreu/caught-you-looking
23
+ Project-URL: Issues, https://github.com/safreu/caught-you-looking/issues
24
+ Description-Content-Type: text/markdown
25
+
26
+ # Caught You Looking
27
+
28
+ [![CI](https://github.com/safreu/caught-you-looking/actions/workflows/ci.yml/badge.svg)](https://github.com/safreu/caught-you-looking/actions/workflows/ci.yml)
29
+ [![License: MIT](https://img.shields.io/badge/License-MIT-blue.svg)](LICENSE)
30
+ [![Python](https://img.shields.io/badge/Python-3.14+-blue.svg)](https://www.python.org/)
31
+
32
+ Caught You Looking (`cyl`) is a lightweight utility for Hyprland that automatically focuses monitors based on your head orientation. It uses a webcam and computer vision to determine which monitor you are looking towards, allowing you to switch monitor focus without using your mouse or keyboard.
33
+
34
+ ## Features
35
+
36
+ - Automatic monitor focusing based on head orientation.
37
+ - Individual calibration for each monitor.
38
+ - Persistent, named calibration profiles for different monitor setups.
39
+ - Configurable dwell time and head pose smoothing.
40
+ - Event-based synchronization with manual Hyprland focus changes.
41
+ - Optional live camera preview.
42
+ - Local processing of webcam frames.
43
+ - Automatic download of the required face landmark model.
44
+
45
+ ## Requirements
46
+
47
+ - Linux with Hyprland
48
+ - Python 3.14 or newer
49
+ - A webcam
50
+ - An internet connection for the initial model download
51
+
52
+ ## Installation
53
+
54
+ ### Using uv
55
+
56
+ Install directly from the GitHub repository:
57
+
58
+ ```sh
59
+ uv tool install git+https://github.com/safreu/caught-you-looking.git
60
+ ```
61
+
62
+ ### From source
63
+
64
+ ```sh
65
+ git clone https://github.com/safreu/caught-you-looking.git
66
+ cd caught-you-looking
67
+ uv sync
68
+ uv run cyl
69
+ ```
70
+
71
+ ## Usage
72
+
73
+ Start the application:
74
+
75
+ ```sh
76
+ cyl
77
+ ```
78
+
79
+ On the first launch, the required face landmark model is downloaded and you are guided through the calibration process.
80
+
81
+ Once calibration is complete, the application automatically focuses the monitor you are looking towards.
82
+
83
+ Stop the application using `Ctrl+C`.
84
+
85
+ ### Calibration
86
+
87
+ During calibration, look towards each monitor as instructed. The application collects multiple head pose samples to determine the representative head orientation for each monitor.
88
+
89
+ Calibration results are saved and reused on subsequent launches.
90
+
91
+ To recalibrate your monitors:
92
+
93
+ ```sh
94
+ cyl --recalibrate
95
+ ```
96
+
97
+ To increase the calibration sampling duration:
98
+
99
+ ```sh
100
+ cyl --recalibrate --duration 5
101
+ ```
102
+
103
+ ### Calibration profiles
104
+
105
+ Different monitor setups can be managed using named calibration profiles.
106
+
107
+ ```sh
108
+ cyl --profile home
109
+ cyl --profile office
110
+ ```
111
+
112
+ If the selected profile does not exist, a new calibration is performed.
113
+
114
+ To list available profiles:
115
+
116
+ ```sh
117
+ cyl --list-profiles
118
+ ```
119
+
120
+ To recalibrate an existing profile:
121
+
122
+ ```sh
123
+ cyl --profile home --recalibrate
124
+ ```
125
+
126
+ ### Camera preview
127
+
128
+ To display the captured webcam video while tracking:
129
+
130
+ ```sh
131
+ cyl --preview
132
+ ```
133
+
134
+ ### Configuration
135
+
136
+ | Argument | Default | Description |
137
+ | --- | --- | --- |
138
+ | `--profile` | `default` | Calibration profile to use. |
139
+ | `--recalibrate` | `false` | Force recalibration of the selected profile. |
140
+ | `--duration` | `2.0` | Calibration sampling duration in seconds per monitor. |
141
+ | `--dwell-time` | `0.6` | Required time in seconds before switching monitor focus. |
142
+ | `--window-size` | `5` | Number of head pose samples used for smoothing. |
143
+ | `--socket-timeout` | `2.0` | Hyprland socket connection timeout in seconds. |
144
+ | `--preview` | `false` | Display a live camera preview. |
145
+ | `--list-profiles` | `false` | List available calibration profiles and exit. |
146
+
147
+ For example, to increase the dwell time and smoothing window:
148
+
149
+ ```sh
150
+ cyl --dwell-time 0.8 --window-size 10
151
+ ```
152
+
153
+ For a complete overview of available arguments:
154
+
155
+ ```sh
156
+ cyl --help
157
+ ```
158
+
159
+ ## How it works
160
+
161
+ Caught You Looking uses MediaPipe's Face Landmarker to estimate the orientation of the user's head from webcam frames.
162
+
163
+ During calibration, representative head poses are recorded for each connected monitor. During tracking, the current head pose is smoothed and compared against these calibrated orientations.
164
+
165
+ A monitor is focused only when it remains the closest matching monitor for the configured dwell time. This reduces unintended focus changes caused by brief head movements.
166
+
167
+ The application also listens to Hyprland's event socket to synchronize its internal tracking state with external monitor focus changes.
168
+
169
+ ## Data storage
170
+
171
+ Application data is stored according to the XDG Base Directory Specification.
172
+
173
+ By default, the following directory structure is used:
174
+
175
+ ```text
176
+ ~/.local/share/cyl/
177
+ ├── calibrations/
178
+ │ ├── default.json
179
+ │ └── ...
180
+ └── models/
181
+ └── face_landmarker.task
182
+ ```
183
+
184
+ If `XDG_DATA_HOME` is configured, its location is used instead of `~/.local/share`.
185
+
186
+ Webcam frames are processed locally and are not uploaded or stored by the application.
187
+
188
+ ## Development
189
+
190
+ Clone the repository and install the development dependencies:
191
+
192
+ ```sh
193
+ git clone https://github.com/safreu/caught-you-looking.git
194
+ cd caught-you-looking
195
+ uv sync --dev
196
+ ```
197
+
198
+ ### Running tests
199
+
200
+ ```sh
201
+ uv run pytest
202
+ ```
203
+
204
+ ### Test coverage
205
+
206
+ ```sh
207
+ uv run pytest --cov
208
+ ```
209
+
210
+ ### Linting
211
+
212
+ ```sh
213
+ uv run ruff check .
214
+ ```
215
+
216
+ ### Formatting
217
+
218
+ ```sh
219
+ uv run ruff format .
220
+ ```
221
+
222
+ ## Limitations
223
+
224
+ Caught You Looking currently estimates head orientation rather than eye gaze. Its accuracy depends on webcam positioning, lighting conditions, calibration quality and the physical arrangement of the monitors.
225
+
226
+ ## License
227
+
228
+ This project is licensed under the MIT License. See [LICENSE](LICENSE) for details.
@@ -0,0 +1,203 @@
1
+ # Caught You Looking
2
+
3
+ [![CI](https://github.com/safreu/caught-you-looking/actions/workflows/ci.yml/badge.svg)](https://github.com/safreu/caught-you-looking/actions/workflows/ci.yml)
4
+ [![License: MIT](https://img.shields.io/badge/License-MIT-blue.svg)](LICENSE)
5
+ [![Python](https://img.shields.io/badge/Python-3.14+-blue.svg)](https://www.python.org/)
6
+
7
+ Caught You Looking (`cyl`) is a lightweight utility for Hyprland that automatically focuses monitors based on your head orientation. It uses a webcam and computer vision to determine which monitor you are looking towards, allowing you to switch monitor focus without using your mouse or keyboard.
8
+
9
+ ## Features
10
+
11
+ - Automatic monitor focusing based on head orientation.
12
+ - Individual calibration for each monitor.
13
+ - Persistent, named calibration profiles for different monitor setups.
14
+ - Configurable dwell time and head pose smoothing.
15
+ - Event-based synchronization with manual Hyprland focus changes.
16
+ - Optional live camera preview.
17
+ - Local processing of webcam frames.
18
+ - Automatic download of the required face landmark model.
19
+
20
+ ## Requirements
21
+
22
+ - Linux with Hyprland
23
+ - Python 3.14 or newer
24
+ - A webcam
25
+ - An internet connection for the initial model download
26
+
27
+ ## Installation
28
+
29
+ ### Using uv
30
+
31
+ Install directly from the GitHub repository:
32
+
33
+ ```sh
34
+ uv tool install git+https://github.com/safreu/caught-you-looking.git
35
+ ```
36
+
37
+ ### From source
38
+
39
+ ```sh
40
+ git clone https://github.com/safreu/caught-you-looking.git
41
+ cd caught-you-looking
42
+ uv sync
43
+ uv run cyl
44
+ ```
45
+
46
+ ## Usage
47
+
48
+ Start the application:
49
+
50
+ ```sh
51
+ cyl
52
+ ```
53
+
54
+ On the first launch, the required face landmark model is downloaded and you are guided through the calibration process.
55
+
56
+ Once calibration is complete, the application automatically focuses the monitor you are looking towards.
57
+
58
+ Stop the application using `Ctrl+C`.
59
+
60
+ ### Calibration
61
+
62
+ During calibration, look towards each monitor as instructed. The application collects multiple head pose samples to determine the representative head orientation for each monitor.
63
+
64
+ Calibration results are saved and reused on subsequent launches.
65
+
66
+ To recalibrate your monitors:
67
+
68
+ ```sh
69
+ cyl --recalibrate
70
+ ```
71
+
72
+ To increase the calibration sampling duration:
73
+
74
+ ```sh
75
+ cyl --recalibrate --duration 5
76
+ ```
77
+
78
+ ### Calibration profiles
79
+
80
+ Different monitor setups can be managed using named calibration profiles.
81
+
82
+ ```sh
83
+ cyl --profile home
84
+ cyl --profile office
85
+ ```
86
+
87
+ If the selected profile does not exist, a new calibration is performed.
88
+
89
+ To list available profiles:
90
+
91
+ ```sh
92
+ cyl --list-profiles
93
+ ```
94
+
95
+ To recalibrate an existing profile:
96
+
97
+ ```sh
98
+ cyl --profile home --recalibrate
99
+ ```
100
+
101
+ ### Camera preview
102
+
103
+ To display the captured webcam video while tracking:
104
+
105
+ ```sh
106
+ cyl --preview
107
+ ```
108
+
109
+ ### Configuration
110
+
111
+ | Argument | Default | Description |
112
+ | --- | --- | --- |
113
+ | `--profile` | `default` | Calibration profile to use. |
114
+ | `--recalibrate` | `false` | Force recalibration of the selected profile. |
115
+ | `--duration` | `2.0` | Calibration sampling duration in seconds per monitor. |
116
+ | `--dwell-time` | `0.6` | Required time in seconds before switching monitor focus. |
117
+ | `--window-size` | `5` | Number of head pose samples used for smoothing. |
118
+ | `--socket-timeout` | `2.0` | Hyprland socket connection timeout in seconds. |
119
+ | `--preview` | `false` | Display a live camera preview. |
120
+ | `--list-profiles` | `false` | List available calibration profiles and exit. |
121
+
122
+ For example, to increase the dwell time and smoothing window:
123
+
124
+ ```sh
125
+ cyl --dwell-time 0.8 --window-size 10
126
+ ```
127
+
128
+ For a complete overview of available arguments:
129
+
130
+ ```sh
131
+ cyl --help
132
+ ```
133
+
134
+ ## How it works
135
+
136
+ Caught You Looking uses MediaPipe's Face Landmarker to estimate the orientation of the user's head from webcam frames.
137
+
138
+ During calibration, representative head poses are recorded for each connected monitor. During tracking, the current head pose is smoothed and compared against these calibrated orientations.
139
+
140
+ A monitor is focused only when it remains the closest matching monitor for the configured dwell time. This reduces unintended focus changes caused by brief head movements.
141
+
142
+ The application also listens to Hyprland's event socket to synchronize its internal tracking state with external monitor focus changes.
143
+
144
+ ## Data storage
145
+
146
+ Application data is stored according to the XDG Base Directory Specification.
147
+
148
+ By default, the following directory structure is used:
149
+
150
+ ```text
151
+ ~/.local/share/cyl/
152
+ ├── calibrations/
153
+ │ ├── default.json
154
+ │ └── ...
155
+ └── models/
156
+ └── face_landmarker.task
157
+ ```
158
+
159
+ If `XDG_DATA_HOME` is configured, its location is used instead of `~/.local/share`.
160
+
161
+ Webcam frames are processed locally and are not uploaded or stored by the application.
162
+
163
+ ## Development
164
+
165
+ Clone the repository and install the development dependencies:
166
+
167
+ ```sh
168
+ git clone https://github.com/safreu/caught-you-looking.git
169
+ cd caught-you-looking
170
+ uv sync --dev
171
+ ```
172
+
173
+ ### Running tests
174
+
175
+ ```sh
176
+ uv run pytest
177
+ ```
178
+
179
+ ### Test coverage
180
+
181
+ ```sh
182
+ uv run pytest --cov
183
+ ```
184
+
185
+ ### Linting
186
+
187
+ ```sh
188
+ uv run ruff check .
189
+ ```
190
+
191
+ ### Formatting
192
+
193
+ ```sh
194
+ uv run ruff format .
195
+ ```
196
+
197
+ ## Limitations
198
+
199
+ Caught You Looking currently estimates head orientation rather than eye gaze. Its accuracy depends on webcam positioning, lighting conditions, calibration quality and the physical arrangement of the monitors.
200
+
201
+ ## License
202
+
203
+ This project is licensed under the MIT License. See [LICENSE](LICENSE) for details.
@@ -0,0 +1,72 @@
1
+ [project]
2
+ name = "caught-you-looking"
3
+ version = "0.1.0"
4
+ description = "Automatic monitor focusing based on head orientation for Hyprland."
5
+ readme = "README.md"
6
+ requires-python = ">=3.14"
7
+ license = "MIT"
8
+ license-files = ["LICENSE"]
9
+ keywords = [
10
+ "hyprland",
11
+ "wayland",
12
+ "head-tracking",
13
+ "computer-vision",
14
+ ]
15
+ classifiers = [
16
+ "Development Status :: 3 - Alpha",
17
+ "Environment :: Console",
18
+ "Operating System :: POSIX :: Linux",
19
+ "Programming Language :: Python :: 3",
20
+ "Programming Language :: Python :: 3.14",
21
+ "Topic :: Desktop Environment",
22
+ ]
23
+ dependencies = [
24
+ "mediapipe>=1.2.3",
25
+ "numpy>=2.5.5",
26
+ "opencv-python>=5.1.0.95",
27
+ "scipy>=1.18.1",
28
+ ]
29
+
30
+ [[project.authors]]
31
+ name = "Samuel Freundel"
32
+ email = "samuel.freundel@uni-ulm.de"
33
+
34
+ [project.urls]
35
+ Homepage = "https://github.com/safreu/caught-you-looking"
36
+ Repository = "https://github.com/safreu/caught-you-looking"
37
+ Issues = "https://github.com/safreu/caught-you-looking/issues"
38
+
39
+ [project.scripts]
40
+ caught-you-looking = "caught_you_looking.main:main"
41
+ cyl = "caught_you_looking.main:main"
42
+
43
+ [build-system]
44
+ requires = ["uv_build>=0.13.10,<0.14.0"]
45
+ build-backend = "uv_build"
46
+
47
+ [tool.pyright]
48
+ venvPath = "."
49
+ venv = ".venv"
50
+ extraPaths = ["src"]
51
+
52
+ [tool.ruff.lint]
53
+ extend-select = ["I"]
54
+
55
+ [tool.pytest.ini_options]
56
+ testpaths = ["tests"]
57
+ addopts = "-ra"
58
+
59
+ [tool.coverage.run]
60
+ source = ["caught_you_looking"]
61
+ branch = true
62
+
63
+ [tool.coverage.report]
64
+ show_missing = true
65
+ skip_covered = true
66
+
67
+ [dependency-groups]
68
+ dev = [
69
+ "pytest>=9.2.0",
70
+ "pytest-cov>=7.1.0",
71
+ "ruff>=0.17.6",
72
+ ]
@@ -0,0 +1,60 @@
1
+ [project]
2
+ name = "caught-you-looking"
3
+ version = "0.1.0"
4
+ description = "Automatic monitor focusing based on head orientation for Hyprland."
5
+ readme = "README.md"
6
+ authors = [{ name = "Samuel Freundel", email = "samuel.freundel@uni-ulm.de" }]
7
+ requires-python = ">=3.14"
8
+ license = "MIT"
9
+ license-files = ["LICENSE"]
10
+ keywords = ["hyprland", "wayland", "head-tracking", "computer-vision"]
11
+ classifiers = [
12
+ "Development Status :: 3 - Alpha",
13
+ "Environment :: Console",
14
+ "Operating System :: POSIX :: Linux",
15
+ "Programming Language :: Python :: 3",
16
+ "Programming Language :: Python :: 3.14",
17
+ "Topic :: Desktop Environment",
18
+ ]
19
+ dependencies = [
20
+ "mediapipe>=1.2.3",
21
+ "numpy>=2.5.5",
22
+ "opencv-python>=5.1.0.95",
23
+ "scipy>=1.18.1",
24
+ ]
25
+
26
+ [project.urls]
27
+ Homepage = "https://github.com/safreu/caught-you-looking"
28
+ Repository = "https://github.com/safreu/caught-you-looking"
29
+ Issues = "https://github.com/safreu/caught-you-looking/issues"
30
+
31
+ [project.scripts]
32
+ caught-you-looking = "caught_you_looking.main:main"
33
+ cyl = "caught_you_looking.main:main"
34
+
35
+ [build-system]
36
+ requires = ["uv_build>=0.13.10,<0.14.0"]
37
+ build-backend = "uv_build"
38
+
39
+ [tool.pyright]
40
+ venvPath = "."
41
+ venv = ".venv"
42
+ extraPaths = ["src"]
43
+
44
+ [tool.ruff.lint]
45
+ extend-select = ["I"]
46
+
47
+ [tool.pytest.ini_options]
48
+ testpaths = ["tests"]
49
+ addopts = "-ra"
50
+
51
+ [tool.coverage.run]
52
+ source = ["caught_you_looking"]
53
+ branch = true
54
+
55
+ [tool.coverage.report]
56
+ show_missing = true
57
+ skip_covered = true
58
+
59
+ [dependency-groups]
60
+ dev = ["pytest>=9.2.0", "pytest-cov>=7.1.0", "ruff>=0.17.6"]
@@ -0,0 +1,2 @@
1
+ def main() -> None:
2
+ print("Hello from caught-you-looking!")
@@ -0,0 +1,59 @@
1
+ from __future__ import annotations
2
+
3
+ from dataclasses import dataclass
4
+
5
+ import cv2
6
+ from mediapipe.tasks.python.vision.face_landmarker import (
7
+ FaceLandmarker,
8
+ )
9
+
10
+ from caught_you_looking.vision.detection import collect_samples
11
+ from caught_you_looking.vision.headpose import HeadPose
12
+
13
+
14
+ @dataclass
15
+ class MonitorCalibration:
16
+ name: str
17
+ pose: HeadPose
18
+
19
+ @classmethod
20
+ def calibrate(
21
+ cls,
22
+ name: str,
23
+ camera: cv2.VideoCapture,
24
+ landmarker: FaceLandmarker,
25
+ duration: float = 2.0,
26
+ ) -> MonitorCalibration:
27
+ input(f"Look at the center of your monitor {name} and press Enter")
28
+
29
+ poses = collect_samples(camera, landmarker, duration)
30
+
31
+ pose = HeadPose.average_pose(poses)
32
+
33
+ return cls(name, pose)
34
+
35
+ def __str__(self) -> str:
36
+ return f"Name: {self.name}, Pose: {self.pose}"
37
+
38
+
39
+ def find_closest_monitor(
40
+ current_pose: HeadPose, calibrations: list[MonitorCalibration]
41
+ ) -> MonitorCalibration:
42
+ if not calibrations:
43
+ raise ValueError("Cannot get minimum without calibrations")
44
+
45
+ return min(
46
+ calibrations, key=lambda calibration: current_pose.distance_to(calibration.pose)
47
+ )
48
+
49
+
50
+ def calibrate_monitors(
51
+ monitors: list[str],
52
+ camera: cv2.VideoCapture,
53
+ landmarker: FaceLandmarker,
54
+ duration: float = 2.0,
55
+ ) -> list[MonitorCalibration]:
56
+ return [
57
+ MonitorCalibration.calibrate(name, camera, landmarker, duration)
58
+ for name in monitors
59
+ ]
@@ -0,0 +1,29 @@
1
+ import json
2
+ from dataclasses import asdict
3
+ from pathlib import Path
4
+
5
+ from caught_you_looking.vision.headpose import HeadPose
6
+
7
+ from .calibration import MonitorCalibration
8
+
9
+
10
+ def save_calibrations(path: Path, calibrations: list[MonitorCalibration]) -> None:
11
+ data = {"monitors": [asdict(calibration) for calibration in calibrations]}
12
+
13
+ path.parent.mkdir(parents=True, exist_ok=True)
14
+
15
+ with path.open("w", encoding="utf-8") as file:
16
+ json.dump(data, file, indent=4)
17
+
18
+
19
+ def load_calibrations(path: Path) -> list[MonitorCalibration]:
20
+ with path.open("r", encoding="utf-8") as file:
21
+ data = json.load(file)
22
+
23
+ return [
24
+ MonitorCalibration(
25
+ name=calibration["name"],
26
+ pose=HeadPose(**calibration["pose"]),
27
+ )
28
+ for calibration in data["monitors"]
29
+ ]