Introduction
The Head Gesture Detection (HGD) library provides a pre-trained model and a simple inference API for detecting head gestures in short videos.
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.
The code snippet below will perform the following:
- Start webcam.
- Collect the needed number of frames (default
60) for the model. - End webcam automatically (or you can press
qto end earlier). - Make prediction of your head gesture and print the result to STDOUT.
from hgd.inference import predict_video
# By default, the following call will download the pre-trained model weights
# and start your webcam. The result is a dictionary.
result = predict_video()
print(result)
# Alternatively, you could provide a pre-recorded video file:
result = predict_video(
"your_head_gesture_video.mp4",
from_beginning=False,
motion_threshold=0.5,
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:
{
'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.
To determine the final gesture:
- If
has_motionprobability is smaller thanmotion_threshold(default0.5),gestureisstationary. Other probabilities are irrelevant. - Otherwise, we will look for the largest probability from
gestures:- If it is smaller than
gesture_threshold(default0.9),gestureisundefined, - else, the corresponding gesture label is selected (e.g.,
nodding).
- If it is smaller than
Release files for hgd 0.2.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| hgd-0.2.0.tar.gz | 6.9 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| hgd-0.2.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 14.9 kB
Release files / hgd-0.2.0.tar.gz
| Download URL | hgd-0.2.0.tar.gz |
|---|---|
| Size | 6.9 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
0897b004d0ecdcf51165f1de83c7c1f0984d20d547d4dc477f251cf6efce3dc5
|
|
BLAKE2b-256 checksum How to use checksums |
e46673a2e222ea482d2dfe8e019f433e36b156b005f91105ea443a65196b7a95
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.0 CPython/3.9.12
|
Release files / hgd-0.2.0-py3-none-any.whl
| Download URL | hgd-0.2.0-py3-none-any.whl |
|---|---|
| Size | 8.0 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
9ba6b82718a09ce8613a52619f3387b83973cad24433b79a6491941dd6ac68e3
|
|
BLAKE2b-256 checksum How to use checksums |
a0406d53a79bf0cb4b311165403c5e138527fa1dcfd94459d7c1d0d5556a350b
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.0 CPython/3.9.12
|