AI
Pass

AI Posture Analyzer — Agent Skill

AI Posture Analyzer — Agent Skill

Analyzes posture from images using MediaPipe for pose detection and AI Pass for intelligent feedback.

Setup

Get your API key: https://aipass.one/panel/developer.html → API Keys

export AIPASS_API_KEY="your-key-here"

Analyze Posture from Image

import cv2
import mediapipe as mp
import requests
import os

AIPASS_API_KEY = os.environ["AIPASS_API_KEY"]

def analyze_posture(image_path):
    """Analyze posture from an image file."""
    
    # Initialize MediaPipe Pose
    mp_pose = mp.solutions.pose
    pose = mp_pose.Pose(static_image_mode=True, min_detection_confidence=0.5)
    
    # Read image
    image = cv2.imread(image_path)
    if image is None:
        return "Error: Could not read image"
    
    # Convert to RGB
    image_rgb = cv2.cvtColor(image, cv2.COLOR_BGR2RGB)
    
    # Detect pose landmarks
    results = pose.process(image_rgb)
    
    if not results.pose_landmarks:
        return "Error: Could not detect pose in image. Please ensure the image shows a full body in standing position."
    
    landmarks = results.pose_landmarks.landmark
    
    # Calculate key measurements
    shoulder_diff = abs(landmarks[11].y - landmarks[12].y)
    hip_diff = abs(landmarks[23].y - landmarks[24].y)
    head_x = landmarks[0].x
    head_y = landmarks[0].y
    left_knee = landmarks[25]
    right_knee = landmarks[26]
    
    # Create analysis prompt
    prompt = f"""Analyze this posture based on these measurements:

Shoulder alignment (Y difference): {shoulder_diff:.3f} (lower is better, ideal < 0.05)
Hip alignment (Y difference): {hip_diff:.3f} (lower is better, ideal < 0.05)
Head position: X={head_x:.3f}, Y={head_y:.3f} (ideal centered around 0.5)
Left knee: X={left_knee.x:.3f}, Y={left_knee.y:.3f}
Right knee: X={right_knee.x:.3f}, Y={right_knee.y:.3f}

Please provide:
1. Overall posture score (0-100)
2. Individual scores for: shoulders, hips, head position, knees, spine alignment
3. Specific issues identified (if any)
4. 3 targeted exercise recommendations to address the issues

Be specific and actionable."""
    
    # Generate AI feedback
    response = requests.post(
        "https://aipass.one/apikey/v1/chat/completions",
        headers={
            "Authorization": f"Bearer {AIPASS_API_KEY}",
            "Content-Type": "application/json"
        },
        json={
            "model": "gpt-5-mini",
            "messages": [
                {"role": "system", "content": "You are a certified posture analyst and physical therapist. Provide clear, professional feedback with actionable advice."},
                {"role": "user", "content": prompt}
            ]
        }
    )
    
    if response.status_code != 200:
        return f"Error generating analysis: {response.text}"
    
    return response.json()["choices"][0]["message"]["content"]

# Example usage
if __name__ == "__main__":
    result = analyze_posture("posture_photo.jpg")
    print(result)

Annotated Output

Create an annotated image showing the detected keypoints:

def create_annotated_image(image_path, output_path="annotated.jpg"):
    """Create an image showing detected pose landmarks."""
    
    mp_pose = mp.solutions.pose
    mp_drawing = mp.solutions.drawing_utils
    pose = mp_pose.Pose(static_image_mode=True, min_detection_confidence=0.5)
    
    image = cv2.imread(image_path)
    image_rgb = cv2.cvtColor(image, cv2.COLOR_BGR2RGB)
    
    results = pose.process(image_rgb)
    
    if results.pose_landmarks:
        # Draw landmarks on image
        mp_drawing.draw_landmarks(
            image, results.pose_landmarks, mp_pose.POSE_CONNECTIONS,
            mp_drawing.DrawingSpec(color=(245,117,66), thickness=2, circle_radius=2),
            mp_drawing.DrawingSpec(color=(245,66,230), thickness=2, circle_radius=2)
        )
        
        cv2.imwrite(output_path, image)
        return f"Annotated image saved to {output_path}"
    
    return "Could not detect pose"

Batch Analysis

Analyze multiple images from a folder:

import glob

def analyze_folder(folder_path):
    """Analyze all images in a folder."""
    
    images = glob.glob(f"{folder_path}/*.jpg") + glob.glob(f"{folder_path}/*.png")
    results = {}
    
    for img_path in images:
        filename = os.path.basename(img_path)
        print(f"Analyzing {filename}...")
        
        analysis = analyze_posture(img_path)
        annotated = create_annotated_image(img_path, f"annotated_{filename}")
        
        results[filename] = {
            "analysis": analysis,
            "annotated_image": annotated
        }
    
    return results

Notes

  • Requires: opencv-python, mediapipe, requests
  • Works with: jpg, png, webp image formats
  • Model: gpt-5-mini (balances quality and cost)
  • Landmarks reference: MediaPipe Pose