Skip to content

Instantly share code, notes, and snippets.

@shubham-kanodia
Created December 4, 2023 07:20
Show Gist options
  • Save shubham-kanodia/33a0890c94227b37541191ce277cbfd6 to your computer and use it in GitHub Desktop.
Save shubham-kanodia/33a0890c94227b37541191ce277cbfd6 to your computer and use it in GitHub Desktop.
Script to find angle
import base64
import requests
class AngleFinder:
def __init__(self):
self.endpoint = "http://pose-tracker-load-balancer-1564941657.us-west-2.elb.amazonaws.com/yoga/angle_calculator"
def convert_image_to_base64(self, image_path):
with open(image_path, "rb") as image_file:
return base64.b64encode(image_file.read()).decode('utf-8')
def calculate_angle(self, image_path, key_point_1, key_point_2, key_point_3, key_point_4):
base64_image = self.convert_image_to_base64(image_path)
response = requests.post(self.endpoint, json={
"encoded_image": base64_image,
"key_point_1": key_point_1,
"key_point_2": key_point_2,
"key_point_3": key_point_3,
"key_point_4": key_point_4
})
return response.json()
angle_finder = AngleFinder()
print(
angle_finder.calculate_angle("../../data/sample-images/ashtanga.jpeg", "left_shoulder", "left_hip", "left_hip", "left_knee")
)
"""
Available Keypoints
"nose",
"left_eye_inner",
"left_eye",
"left_eye_outer",
"right_eye_inner",
"right_eye",
"right_eye_outer",
"left_ear",
"right_ear",
"left_mouth",
"right_mouth",
"left_shoulder",
"right_shoulder",
"left_elbow",
"right_elbow",
"left_wrist",
"right_wrist",
"left_pinky",
"right_pinky",
"left_index",
"right_index",
"left_thumb",
"right_thumb",
"left_hip",
"right_hip",
"left_knee",
"right_knee",
"left_ankle",
"right_ankle",
"left_heel",
"right_heel",
"left_foot_index",
"right_foot_index"
"""
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment