Spaces:
Runtime error
Runtime error
File size: 3,077 Bytes
318f7bc ee83b99 318f7bc 834fd2c 318f7bc ee83b99 834fd2c b58a6f1 834fd2c b58a6f1 834fd2c ee83b99 834fd2c ee83b99 834fd2c ee83b99 b58a6f1 a5c423f 834fd2c 36faed1 834fd2c b58a6f1 a5c423f 834fd2c a5c423f b58a6f1 ee83b99 834fd2c ee83b99 b58a6f1 ee83b99 834fd2c ee83b99 318f7bc c62fd9d 834fd2c c62fd9d ee83b99 c62fd9d 834fd2c 318f7bc 834fd2c |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 |
import math
import numpy as np
import cv2
from tensorflow.keras import preprocessing
def euclidean_distance(point1, point2):
return math.sqrt((point2[0] - point1[0]) ** 2 + (point2[1] - point1[1]) ** 2)
def convert_to_real_measurements(pixel_measurement, pixel_height, real_height_cm):
height_ratio = real_height_cm / pixel_height
return pixel_measurement * height_ratio
def measure_body_sizes(side_colored_mask, front_colored_mask, sideposes, frontposes, real_height_cm, rainbow=None):
"""Measure various body sizes based on detected poses."""
measurements = []
# Check if poses are available
if not frontposes or len(frontposes) == 0:
return measurements
for pose in frontposes:
keypoints = pose[0] # Directly accessing keypoints
# Extracting position coordinates
try:
left_eye = (keypoints[1].position.x, keypoints[1].position.y)
right_eye = (keypoints[2].position.x, keypoints[2].position.y)
left_shoulder = (keypoints[5].position.x, keypoints[5].position.y)
right_shoulder = (keypoints[6].position.x, keypoints[6].position.y)
left_wrist = (keypoints[9].position.x, keypoints[9].position.y)
left_hip = (keypoints[11].position.x, keypoints[11].position.y)
right_hip = (keypoints[12].position.x, keypoints[12].position.y)
left_ankle = (keypoints[15].position.x, keypoints[15].position.y)
right_ankle = (keypoints[16].position.x, keypoints[16].position.y)
except (IndexError, AttributeError):
continue
# Calculate pixel height
pixel_height = euclidean_distance(left_eye, left_ankle)
# Calculate measurements
shoulder_width_cm = convert_to_real_measurements(
euclidean_distance(left_shoulder, right_shoulder),
pixel_height, real_height_cm
)
arm_length_cm = convert_to_real_measurements(
euclidean_distance(left_shoulder, left_wrist),
pixel_height, real_height_cm
)
leg_length_cm = convert_to_real_measurements(
euclidean_distance(left_hip, left_ankle),
pixel_height, real_height_cm
)
shoulder_to_waist_cm = convert_to_real_measurements(
euclidean_distance(left_shoulder, left_hip),
pixel_height, real_height_cm
)
# Simplified waist circumference - needs more accurate implementation
waist_width = euclidean_distance(left_hip, right_hip)
waist_circumference_cm = convert_to_real_measurements(
waist_width, pixel_height, real_height_cm
) * 2 # Rough estimate
measurements.append({
"height_cm": real_height_cm,
"arm_length_cm": arm_length_cm,
"shoulder_width_cm": shoulder_width_cm,
"shoulder_to_waist_cm": shoulder_to_waist_cm,
"leg_length_cm": leg_length_cm,
"waist_circumference_cm": waist_circumference_cm
})
return measurements |