Skip to main content

Ocular Gesture Modules (OGM) - API for eye gesture detection.

Project description

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:

pip install .

Alternatively:

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):

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 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.


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 my website.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

ogm_vision-0.1.2.tar.gz (3.4 MB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

ogm_vision-0.1.2-py3-none-any.whl (3.3 MB view details)

Uploaded Python 3

File details

Details for the file ogm_vision-0.1.2.tar.gz.

File metadata

  • Download URL: ogm_vision-0.1.2.tar.gz
  • Upload date:
  • Size: 3.4 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.13

File hashes

Hashes for ogm_vision-0.1.2.tar.gz
Algorithm Hash digest
SHA256 b10542bdec949746dddb74546eae20a6d1f0194c7b4e30d85cea85405c850825
MD5 e8dd30b9116dcce5330134564bb61c88
BLAKE2b-256 b81f158be66a51a2ab5624fc7d69f7a25dd225832ad12d4f184bf48cfeee2c61

See more details on using hashes here.

File details

Details for the file ogm_vision-0.1.2-py3-none-any.whl.

File metadata

  • Download URL: ogm_vision-0.1.2-py3-none-any.whl
  • Upload date:
  • Size: 3.3 MB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.13

File hashes

Hashes for ogm_vision-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 b70e6ce9369401eabbbd26a3c4cdabe6b56745b034cdb1ddfec4438204c2c8dc
MD5 18403aee80c84c230fbd63935d75530d
BLAKE2b-256 632d3bf761338b67461ff42fceed4e71d3eff76858de9817dd18208fb29a9029

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page