Skip to main content

Detection and classification of head gestures in videos

Project description

ci License MIT 1.0

Introduction

The Head Gesture Detection (HGD) library provides a pre-trained model and a simple inference API for detecting head gestures in short videos. Under the hood, it uses Google MediaPipe for collecting the landmark features.

Installation

Tested for Python 3.8, 3.9, and 3.10.

The best way to install HGD with its dependencies is from PyPI:

python3 -m pip install --upgrade hgd

Alternatively, to obtain the latest version from this repository:

git clone git@github.com:bhky/head-gesture-detection.git
cd head-gesture-detection
python3 -m pip install .

Usage

An easy way to try this library and the pre-trained model is to make a short video with your head gesture.

Webcam

The code snippet below will perform the following:

  • Search for the pre-trained weights file from $HOME/.hgd/weights, if not exists, the file will be downloaded from this repository.
  • Start webcam.
  • Collect the needed number of frames (default 60) for the model.
  • End webcam automatically (or you can press q to end earlier).
  • Make prediction of your head gesture and print the result to STDOUT.
from hgd.inference import predict_video

result = predict_video()
print(result)

Video file

Alternatively, you could provide a pre-recorded video file:

from hgd.inference import predict_video

result = predict_video(
  "your_head_gesture_video.mp4",
  from_beginning=False,
  motion_threshold=0.5,  # Optionally tune the thresholds.
  gesture_threshold=0.9
)
# The `from_beginning` flag controls whether the needed frames will be obtained
# from the beginning or toward the end of the video.
# Thresholds can be adjusted as needed, see explanation below.

Result format

The result is returned as a Python dictionary.

{
  'gesture': 'turning',
  'probabilities': {
    'has_motion': 1.0,
    'gestures': {
      'nodding': 0.009188028052449226,
      'turning': 0.9908120036125183
    }
  }
}

Head gestures

The following gesture types are available:

  • nodding - Repeatedly tilt your head upward and downward.
  • turning - Repeatedly turn your head leftward and rightward.
  • stationary - Not tilting or turning your head; translation motion is still treated as stationary.
  • undefined - Unrecognised gesture or no landmarks detected (usually means no face is shown).

To determine the final gesture:

  • If has_motion probability is smaller than motion_threshold (default 0.5), gesture is stationary. Other probabilities are irrelevant.
  • Otherwise, we will look for the largest probability from gestures:
    • If it is smaller than gesture_threshold (default 0.9), gesture is undefined,
    • else, the corresponding gesture label is selected (e.g., nodding).
  • If no landmarks are detected in the video, gesture is undefined. The probabilities dictionary is empty.

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

hgd-0.4.0.tar.gz (7.3 kB view details)

Uploaded Source

Built Distribution

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

hgd-0.4.0-py3-none-any.whl (8.5 kB view details)

Uploaded Python 3

File details

Details for the file hgd-0.4.0.tar.gz.

File metadata

  • Download URL: hgd-0.4.0.tar.gz
  • Upload date:
  • Size: 7.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.0 CPython/3.9.12

File hashes

Hashes for hgd-0.4.0.tar.gz
Algorithm Hash digest
SHA256 596c5828fb657e06c25a63fb3bbfad7858a023f29e8376ce6404f27e9362aaa1
MD5 c97a6cb3f6247f0486b0420fd5995355
BLAKE2b-256 629846ddd57d22a6e4a630ed974927e9984824aa3750badde9f62dc08737a651

See more details on using hashes here.

File details

Details for the file hgd-0.4.0-py3-none-any.whl.

File metadata

  • Download URL: hgd-0.4.0-py3-none-any.whl
  • Upload date:
  • Size: 8.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.0 CPython/3.9.12

File hashes

Hashes for hgd-0.4.0-py3-none-any.whl
Algorithm Hash digest
SHA256 55067355a17ab8b65912dc656b2ad9516903da4b26601b5f7f79096e182a608b
MD5 c3d87cfa7dc2d3d1f06e09af53645908
BLAKE2b-256 29e6d653a2522c1c9da8158ceaf523dc03f855f985af17c34e7f80a8c99910d9

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