Ocular Gesture Modules (OGM) - API for eye gesture detection.
Project description
Ocular Gesture Modules (OGM)
OGM is a Python API 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):
### file_name: main.py
#
import time
from ogm import ActionType, BlinkDetector, CameraConfig
# Initialize the detector - For greater accuracy, you should adjust these 3 parameters.
# See the DocStrings for more info about them (i'm lazy).
blink_detector = BlinkDetector(
ear_diff=0.05, calibration_threshold_ratio=0.60, sensitivity_coefficient=0.15
)
# Define the callback for automatic calibration
def on_calibration(left_eye: float, right_eye: float):
blink_detector.left_ear_threshold = left_eye
blink_detector.right_ear_threshold = right_eye
print(f"Calibration finished.\nLeft EAR: {left_eye}, Right EAR: {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 and hand 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:
- Blinking gestures module <-- Major features implemented!
- Hand movement gestures module. (v0.2.0)
- Eyebrow movement gestures module. (v0.3.0)
- Eye movement gestures module. (v0.4.0)
- Rewriting the core API in C++ and Rust. (v1.0.0)
- Creating bindings for JavaScript. (v1.1.0)
- Creating bindings for Dart (v1.2.0)
###
# 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
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file ogm_vision-0.1.3.tar.gz.
File metadata
- Download URL: ogm_vision-0.1.3.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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
be2f820fe46ffa3cb8a3f4c991d8a7031beb655b175edcd9c3f50ad8064563c1
|
|
| MD5 |
45d92824b1d44dbf10607f45b2347f53
|
|
| BLAKE2b-256 |
f15692c234ed2c0a7dc9df03424a2819031aabb645d1e84321ca09e08d2af451
|
File details
Details for the file ogm_vision-0.1.3-py3-none-any.whl.
File metadata
- Download URL: ogm_vision-0.1.3-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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
627762761f6ea90e281636a2f2a9e0a1799f8fee76471f6beadb2399cb09b8a3
|
|
| MD5 |
69a95d6bfc67def55978ac4c78b5297f
|
|
| BLAKE2b-256 |
75b62d9eebeaf1cd23a0617a1486622da6b858602545f881ec618b561b1584a6
|