Update app.py
Browse files
app.py
CHANGED
|
@@ -9,17 +9,6 @@ import math
|
|
| 9 |
################
|
| 10 |
|
| 11 |
def calculate_angle(point1, point2, point3):
|
| 12 |
-
"""
|
| 13 |
-
Calculates the angle at point2 formed by the lines connecting it to point1 and point3.
|
| 14 |
-
|
| 15 |
-
Args:
|
| 16 |
-
point1 (tuple): Coordinates (x, y) of the first point.
|
| 17 |
-
point2 (tuple): Coordinates (x, y) of the vertex (the point where the angle is).
|
| 18 |
-
point3 (tuple): Coordinates (x, y) of the third point.
|
| 19 |
-
|
| 20 |
-
Returns:
|
| 21 |
-
float: The angle in degrees.
|
| 22 |
-
"""
|
| 23 |
x1, y1 = point1
|
| 24 |
x2, y2 = point2
|
| 25 |
x3, y3 = point3
|
|
@@ -196,7 +185,7 @@ def calculate_angles_landmarks(landmarks):
|
|
| 196 |
|
| 197 |
# Function to calculate the angles for both left and right sides and overlay on image
|
| 198 |
def calculate_and_display_angles(image1, return_angles=False):
|
| 199 |
-
|
| 200 |
|
| 201 |
mp_pose = mp.solutions.pose
|
| 202 |
pose = mp_pose.Pose(min_detection_confidence=0.5, min_tracking_confidence=0.5)
|
|
@@ -211,7 +200,7 @@ def calculate_and_display_angles(image1, return_angles=False):
|
|
| 211 |
# landmarks = results.pose_landmarks
|
| 212 |
########
|
| 213 |
ang , locs = calculate_angles_landmarks(results.pose_landmarks)
|
| 214 |
-
|
| 215 |
#if only angles needed
|
| 216 |
if return_angles:
|
| 217 |
return ang
|
|
@@ -219,7 +208,9 @@ def calculate_and_display_angles(image1, return_angles=False):
|
|
| 219 |
# Draw the pose landmarks on the image
|
| 220 |
mp_drawing = mp.solutions.drawing_utils
|
| 221 |
mp_drawing.draw_landmarks(image, results.pose_landmarks, mp_pose.POSE_CONNECTIONS)
|
| 222 |
-
|
|
|
|
|
|
|
| 223 |
# Display the angle values at corresponding locations
|
| 224 |
def overlay_angle(angle, location, color=(0, 255, 0)):
|
| 225 |
# Coordinates are normalized, scale them to the image size
|
|
|
|
| 9 |
################
|
| 10 |
|
| 11 |
def calculate_angle(point1, point2, point3):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 12 |
x1, y1 = point1
|
| 13 |
x2, y2 = point2
|
| 14 |
x3, y3 = point3
|
|
|
|
| 185 |
|
| 186 |
# Function to calculate the angles for both left and right sides and overlay on image
|
| 187 |
def calculate_and_display_angles(image1, return_angles=False):
|
| 188 |
+
|
| 189 |
|
| 190 |
mp_pose = mp.solutions.pose
|
| 191 |
pose = mp_pose.Pose(min_detection_confidence=0.5, min_tracking_confidence=0.5)
|
|
|
|
| 200 |
# landmarks = results.pose_landmarks
|
| 201 |
########
|
| 202 |
ang , locs = calculate_angles_landmarks(results.pose_landmarks)
|
| 203 |
+
|
| 204 |
#if only angles needed
|
| 205 |
if return_angles:
|
| 206 |
return ang
|
|
|
|
| 208 |
# Draw the pose landmarks on the image
|
| 209 |
mp_drawing = mp.solutions.drawing_utils
|
| 210 |
mp_drawing.draw_landmarks(image, results.pose_landmarks, mp_pose.POSE_CONNECTIONS)
|
| 211 |
+
|
| 212 |
+
return image
|
| 213 |
+
|
| 214 |
# Display the angle values at corresponding locations
|
| 215 |
def overlay_angle(angle, location, color=(0, 255, 0)):
|
| 216 |
# Coordinates are normalized, scale them to the image size
|