Metadata-Version: 2.4
Name: gestureplaykit
Version: 1.0.0
Summary: Friendly Python webcam, gesture tracking, mouth tracking, and image overlays for creative apps
Author: GesturePlayKit contributors
License-Expression: MIT
Keywords: gestures,webcam,hand tracking,mediapipe,AR,computer vision
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3 :: Only
Classifier: Operating System :: OS Independent
Classifier: Intended Audience :: Developers
Classifier: Topic :: Multimedia :: Graphics
Requires-Python: >=3.10
Description-Content-Type: text/markdown
License-File: LICENSE
Requires-Dist: mediapipe>=0.10.20
Requires-Dist: numpy<3,>=1.26
Requires-Dist: opencv-contrib-python<5,>=4.8
Provides-Extra: test
Requires-Dist: pytest>=8; extra == "test"
Dynamic: license-file

# GesturePlayKit 1.0.0 🖐️

**Build Python webcam games and interactive art without writing the MediaPipe setup yourself.** GesturePlayKit gives you clear, readable hand gestures, mouth state, drawing functions, and tiny geometry helpers. You write the actual program, its rules, menus, and score.

> **Release status:** v1.0.0 source package and distribution archives are prepared. This repository/ZIP by itself **does not publish** anything to PyPI.

## Install

Python **3.10+** on Windows, macOS or Linux (subject to the availability of MediaPipe wheels for your OS/Python version):

```powershell
python -m pip install .
```

If you publish v1.0.0 to PyPI later, users can install it with `python -m pip install gestureplaykit==1.0.0`.

Download the official Google hand and face models **once**:

```powershell
python -m gestureplaykit download-models
```

This creates `models/hand_landmarker.task` and `models/face_landmarker.task`. Afterwards, webcam tracking works offline. Downloading images by URL still requires internet.

Or download only one tracking model:

```powershell
python -m gestureplaykit download-models --hands-only
python -m gestureplaykit download-models --faces-only
```

If your script lives in another directory, pass a model folder explicitly: `Vision(models_dir="C:/path/to/models")`. The default is `models` relative to your **current working directory**.

## First program

Create `hello.py` next to the `models` folder:

```python
from gestureplaykit import Camera, Vision, show_text, draw_hand

with Camera() as camera, Vision(models_dir="models") as vision:
    while True:
        frame = camera.read()
        if frame is None:
            break

        vision.update(frame)
        hand = vision.hand
        if hand:
            draw_hand(frame, hand)
            if hand.pinch_started:
                print("Pinch started!")
            if hand.pinching:
                show_text(frame, "PINCHING!", at=(15, 70))
            if hand.double_pinched:
                print("Double pinch!")

        if vision.face and vision.face.mouth_open:
            show_text(frame, "MOUTH OPEN", at=(15, 105))
        if not camera.show(frame, title="My gesture app"):
            break
```

Press **Q** or **Escape** to close the window. The camera requires local webcam permission.

## Quick reference

| Purpose | Example |
|---|---|
| Open camera | `with Camera(index=0) as camera:` |
| Read frame | `frame = camera.read()` |
| Analyze frame | `vision.update(frame)` |
| First hand | `vision.hand` (or `None`) |
| Multiple hands | `for hand in vision.hands:` |
| Pinching now | `hand.pinching` |
| New pinch this frame | `hand.pinch_started` |
| Release this frame | `hand.pinch_ended` |
| Double-pinch this frame | `hand.double_pinched` |
| Pinch position | `hand.pinch_center` |
| Palm position | `hand.palm_center` |
| Thumb tip | `hand.landmark(4)` |
| Index tip | `hand.landmark(8)` |
| Two landmarks touching | `hand.touching(4, 12)` |
| Finger extended | `hand.finger_up("index")` |
| All finger estimates | `hand.fingers_up` |
| Open palm / fist | `hand.open_palm` / `hand.fist` |
| Estimated hand ID | `hand.id` |
| Mouth open | `face.mouth_open` |
| Mouth opened this frame | `face.mouth_just_opened` |
| Mouth closed this frame | `face.mouth_just_closed` |
| Mouth center | `face.mouth_center` |
| Point near mouth | `face.near_mouth((x, y), 50)` |
| Load local/URL picture | `load_picture("chip.png")` |
| Change picture size | `resize_picture(chip, (90, 90))` |
| Draw with transparency | `show_picture(frame, chip, at=(x,y), opacity=0.7)` |
| Draw text | `show_text(frame, "HI!", at=(15,30))` |
| Draw point / line | `show_point(...)`, `show_line(...)` |
| Draw rectangle | `show_rectangle(frame, (0,0,100,50))` |
| Draw hand outline | `draw_hand(frame, hand, number_landmarks=True)` |
| Geometry | `distance(a,b)`, `clamp(v,0,1)`, `inside_rectangle(point,rect)` |
| Reset tracking history | `vision.reset()` |

## v1 additions

- Draw a full hand skeleton and optional landmark numbers with `draw_hand`.
- Estimate each raised finger, an open palm, or a fist.
- New drawing primitives: `show_line`, `show_rectangle`, `resize_picture`, and opacity in `show_picture`.
- New geometry helpers: `distance`, `clamp`, `inside_rectangle`.
- Best-effort, frame-to-frame tracking IDs for multiple hands so gesture state is less likely to transfer to the wrong hand when tracker result order changes.
- Sensible parameter validation, safer image loading, improved model download logic, expanded tests, and simple CLI model downloads.
- Fully maintains the previous v0.1 public calls and default parameters. See `CHANGELOG.md` and `UPGRADING.md`.

## Multiple hands

```python
vision.update(frame)
for hand in vision.hands:
    if hand.pinching:
        show_picture(frame, sprite, at=hand.pinch_center)
```

`hand.id` is **not** an identifying characteristic of a human. It's a best-effort temporary number for one tracked hand; IDs may change when hands overlap, move quickly or leave view. `vision.hand` continues to be the first detected hand.

## Load images from the internet

```python
from gestureplaykit import load_picture, show_picture

sprite = load_picture("https://example.org/direct-image.png", size=(120, 120))
# Do this outside your camera loop to avoid network delay.
show_picture(frame, sprite, at=(200, 150), opacity=0.85)
```

The URL must return actual image bytes (not an HTML page). Only HTTP(S) image downloads are supported; local PNG/JPEG images work offline. Decoded images are cached, and the caller receives a copy. Image files are limited to 15 MB and 40 million decoded pixels.

## Accuracy and privacy

GesturePlayKit computes approximate pinches and mouth opening from **2-D landmarks**, not actual physical contact or eating. Performance depends on lighting, hand pose, occlusion, and camera speed. Open-palm/fist estimates are especially approximate when the hand is edge-on. The two-hand ID matcher uses nearest-palm matching and may swap IDs when hands cross.

MediaPipe processes the webcam feed locally. GesturePlayKit does **not** upload camera frames. `download_models` and image URL downloads make requests to the host you specify.

## Build, test, contribute

```powershell
python -m pip install -e ".[test]"
python -m pytest -q
python -m pip install build twine
python -m build
python -m twine check dist/*
```

See [PUBLISH_TO_PYPI.md](PUBLISH_TO_PYPI.md) for the upload steps, [AI_ATTRIBUTION.md](AI_ATTRIBUTION.md) for provenance, and [CONTRIBUTING.md](CONTRIBUTING.md) for development guidance.

**Competition note:** This library was written with substantial AI assistance. Open-sourcing it or releasing a v1 does not turn that source into independent student-authored work. Applications can use it as a documented dependency, but you should personally write and understand the meaningful application logic and follow your competition's disclosure rules.
