Metadata-Version: 2.4
Name: ogm-vision
Version: 0.1.2
Summary: Ocular Gesture Modules (OGM) - API for eye gesture detection.
Author-email: Valerio Di Tommaso <contact.me@valerioditommaso.dev>
License: MIT License
        
        Copyright (c) 2026 Valerio Di Tommaso
        
        Permission is hereby granted, free of charge, to any person obtaining a copy
        of this software and associated documentation files (the "Software"), to deal
        in the Software without restriction, including without limitation the rights
        to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
        copies of the Software, and to permit persons to whom the Software is
        furnished to do so, subject to the following conditions:
        
        The above copyright notice and this permission notice shall be included in all
        copies or substantial portions of the Software.
        
        THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
        IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
        FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
        AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
        LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
        OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
        SOFTWARE.
        
Project-URL: Homepage, https://github.com/gyratina/Ocular-Gesture-Modules
Project-URL: Repository, https://github.com/gyratina/Ocular-Gesture-Modules
Project-URL: Bug Tracker, https://github.com/gyratina/Ocular-Gesture-Modules/issues
Classifier: Programming Language :: Python :: 3
Classifier: License :: OSI Approved :: MIT License
Classifier: Operating System :: OS Independent
Classifier: Topic :: Scientific/Engineering :: Image Recognition
Requires-Python: >=3.10
Description-Content-Type: text/markdown
License-File: LICENSE
Requires-Dist: mediapipe
Requires-Dist: opencv-python
Requires-Dist: numpy
Requires-Dist: scipy
Dynamic: license-file

# Ocular Gesture Modules (OGM)

**OGM** is a Python API (for now) that allows the implementation of highly customizable eye gestures.

Currently, OGM supports only blinking gestures. These are fully customizable, allowing the API user to build potentially infinite combinations of actions (RAM permitting).

---

## Installation
If you download this repository, navigate inside and run:

```bash
pip install .
```

Alternatively:
```bash
pip install ogm-vision
```


---

## Usage

> [!WARNING]
> **OGM IS IN ACTIVE DEVELOPMENT**
> 
> It is highly likely that the way to do certain things with OGM might change frequently across versions, as the library is still in early development.
> To get an idea of what's coming, check out the roadmap below.

I have included DocStrings within the API files, so if any information is missing here, you should still have access to everything you need right in your IDE.

***Usage Example (Calibration & Detection):***
```python
import time
from ogm import ActionType, BlinkDetector, CameraConfig

# Initialize the detector - You can adjust the threshold severity here if needed
blink_detector = BlinkDetector(calibration_threshold_ratio=0.60)

# Define the callback for automatic calibration
def on_calibration(left_eye: float, right_eye: float):
    print(f"Calibration finished.\nLeft EAR: {left_eye:.3f}, Right EAR: {right_eye:.3f}")
    blink_detector.left_ear_threshold = left_eye
    blink_detector.right_ear_threshold = right_eye

# Define the callback to handle gesture sequences
def on_actions(actions: list[tuple[ActionType, int]]):
    match actions:
        # Single blink of the left eye
        case [(ActionType.LEFT, _)]:
            print("Action: LEFT BLINK")
            blink_detector.reset_log()

        # Single blink of both eyes
        case [(ActionType.BOTH, _)]:
            print("Action: BOTH EYES BLINK")
            blink_detector.reset_log()

        # Combo example: Right eye + Left eye (max pause 800ms)
        case [*_, (ActionType.RIGHT, p), (ActionType.LEFT, _)] if p <= 800:
            print(f"Action: RIGHT -> LEFT (pause: {p}ms)")
            blink_detector.reset_log()

        # Wait state: The user blinked the right eye, waiting for combo
        case [*_, (ActionType.RIGHT, _)]:
            print("Waiting for complete combo...")
            pass

        # Ignore any other sequence
        case _:
            pass

if __name__ == "__main__":
    # Bind callbacks
    blink_detector.on_blink = on_actions
    blink_detector.on_calibration_callback = on_calibration
    
    # Configure camera (use 0 for default webcam)
    my_camera = CameraConfig()
    
    # Calibration Phase
    print("Starting Calibration. Please look at the camera with a neutral expression for 3 seconds...")
    blink_detector.start(mode="calibrate", camera_config=my_camera)
    
    # Wait for the background thread to finish the 3-second calibration
    time.sleep(3.5)
    
    # Safely close the calibration thread and release resources
    blink_detector.close()
    
    # Gesture Detection Phase
    print("Starting Gesture Detection...")
    blink_detector.start(mode="detect", camera_config=my_camera)
    
    try:
        # Keep the main thread alive while the background daemon thread does the work.
        # ---> YOU CAN RUN YOUR OWN APPLICATION LOOP OR GUI HERE <---
        while True:    # This cycle is only for testing the API
            time.sleep(1)
    except KeyboardInterrupt:
        print("\nExiting...")
    finally:
        # Always remember to safely release resources on exit
        blink_detector.close()
```

---

## Acknowledgments & Legal
This library is built as a wrapper and mathematical layer on top of [Google MediaPipe](https://developers.google.com/mediapipe) for high-performance, real-time facial landmark detection. 

The OGM library bundles the `face_landmarker.task` model, which is provided by Google under the **Apache License 2.0**. 
For more details, please refer to the official [MediaPipe repository](https://github.com/google-ai-edge/mediapipe).

---

## Development Roadmap
The roadmap I have set for the development of this API is:
1. Blinking gestures module <-- **In Testing Phase**
2. Eye movement gestures module.
3. Eyebrow movement gestures module.
4. Hand movement gestures module.
5. Rewriting the core API in C++/Rust (yet to be decided).
6. Creating bindings for C++/Rust to other languages.

---

```
###
# project: Ocular Gesture Modules (OGM)
# project-start: 2026-06-26 (yyyy-mm-dd)
# author-username: @gyratina on GitHub
# author-name: Valerio Di Tommaso
# author-email: contact.me@valerioditommaso.dev
###
```

**To learn more about me, check <a href="https://valerioditommaso.dev/en">my website</a>.**
