Skip to main content

A collection of tools related to pose detection in images

Project description

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_downloader to download the model asset from Google Drive.
  • Assumes the pose_landmarker.task file 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

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

noahs_pose_detector-0.1.0.tar.gz (6.2 kB view details)

Uploaded Source

Built Distribution

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

noahs_pose_detector-0.1.0-py3-none-any.whl (6.8 kB view details)

Uploaded Python 3

File details

Details for the file noahs_pose_detector-0.1.0.tar.gz.

File metadata

  • Download URL: noahs_pose_detector-0.1.0.tar.gz
  • Upload date:
  • Size: 6.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.11.4

File hashes

Hashes for noahs_pose_detector-0.1.0.tar.gz
Algorithm Hash digest
SHA256 6ccef4e667289bb3770f3ce45f9249701d7d3ae7aa272bdda2a63fca963f574b
MD5 c83ce1a27333b5e7c8c31b1feb43bb0e
BLAKE2b-256 be84533ec5411a10c89b3acd1546011cb19ccd0e017977514c74b643303445da

See more details on using hashes here.

File details

Details for the file noahs_pose_detector-0.1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for noahs_pose_detector-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 cc26dc4df9df01bfdb683bb536b60b7c52adfa3ac00955b70d1dc430b24aa9bf
MD5 e1ee56ba4c6cfc8db6e3ea155b82c2e7
BLAKE2b-256 ee6bd0f512e956d66e7662edb01d2c06c0f0adbafc1e348b41c137cb164af1d8

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