Pose Detection Utility with MediaPipe
This project provides a Python utility for pose detection and analysis using MediaPipe's PoseLandmarker model. It supports loading pose detection models, extracting and visualizing pose landmarks, creating segmentation masks, estimating face direction, and working with image files directly or as bytes.
Features
- Automatically downloads the pose detection model
- Detects human pose landmarks in static images
- Overlays pose landmarks on original or black background images
- Creates segmentation masks (foreground/background)
- Extracts pose landmark coordinates
- Reconstructs poses from landmark coordinates
- Estimates face direction (LEFT, RIGHT, CENTER)
Dependencies
- mediapipe
- opencv-python
- numpy
Installation
pip install noahs_pose_detector
Example Usage
from noahs_pose_detector import PoseDetector
# instantiate Pose Detector object
d = PoseDetector()
# generating pose masks and inverse pose masks from images
# great for creating mask for the human subject or background
mask = d.convert_image_to_mask("image.jpg","image_mask.jpg")
mask = d.convert_image_to_mask("image.jpg","image_mask_inverse.jpg",inverse=True)
# generate an image of the pose points with a black background
pose = d.convert_image_to_pose("image.jpg","image_pose.jpg")
# generate an image of the pose points on top of the original image
image_with_pose = d.add_pose_on_top_of_image("image.jpg","image_with_pose.jpg")
# extract pose point locations and then generate the pose image from extracted points
points = d.get_pose_points("image.jpg")
points_image = d.render_pose_from_points(points, image_size=(640,960), output_file="image_rendered_pose.jpg")
# extract pose point locations then determine face orientation based on them
# perspective = "3rd" means direction will be from the camera's perspective
# perspective = "1st" means the direction will be from the subject's perspective
# possible direction outputs are (LEFT, RIGHT, CENTER)
direction = d.get_face_direction_from_pose_points(points,threshold=0.15, perspective="3rd")
print(f"Face is facing: {direction}")
# the get_pose_points method can also be used on image bytes directly
with open("image.jpg", "rb") as f:
image_bytes = f.read()
pose_points_from_bytes = d.get_pose_points(image_bytes)
print(pose_points_from_bytes)
Notes
- Uses a helper module
noahs_google_drive_downloaderto download the model asset from Google Drive. - Assumes the
pose_landmarker.taskfile is downloaded or available in the working directory. - The segmentation mask is returned as a 3-channel grayscale image for easy visualization.
- This script is ideal for gesture analysis
Metadata
Release files for noahs-pose-detector 0.1.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 | Provenance | Actions |
|---|---|---|---|---|
| noahs_pose_detector-0.1.0.tar.gz | 6.2 kB | Without provenance | Details for noahs_pose_detector-0.1.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| noahs_pose_detector-0.1.0-py3-none-any.whl | Python 3 | none | any | Details for noahs_pose_detector-0.1.0-py3-none-any.whl |
Total release size: 13.0 kB
Release files / noahs_pose_detector-0.1.0.tar.gz
| Download URL | noahs_pose_detector-0.1.0.tar.gz |
|---|---|
| Size | 6.2 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
6ccef4e667289bb3770f3ce45f9249701d7d3ae7aa272bdda2a63fca963f574b
|
|
BLAKE2b-256 checksum How to use checksums |
be84533ec5411a10c89b3acd1546011cb19ccd0e017977514c74b643303445da
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.11.4
|
Release files / noahs_pose_detector-0.1.0-py3-none-any.whl
| Download URL | noahs_pose_detector-0.1.0-py3-none-any.whl |
|---|---|
| Size | 6.8 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
cc26dc4df9df01bfdb683bb536b60b7c52adfa3ac00955b70d1dc430b24aa9bf
|
|
BLAKE2b-256 checksum How to use checksums |
ee6bd0f512e956d66e7662edb01d2c06c0f0adbafc1e348b41c137cb164af1d8
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.11.4
|
Security for noahs-pose-detector 0.1.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.