Spaces:
Runtime error
Runtime error
Update calculations.py
Browse files- calculations.py +31 -25
calculations.py
CHANGED
|
@@ -46,31 +46,31 @@ def measure_body_sizes(side_colored_mask, front_colored_mask, sideposes, frontpo
|
|
| 46 |
pixel_height, real_height_cm
|
| 47 |
)
|
| 48 |
|
| 49 |
-
# arm_length_cm = convert_to_real_measurements(
|
| 50 |
-
# euclidean_distance((right_shoulder.x, right_shoulder.y), (right_elbow.x, right_elbow.y)),
|
| 51 |
-
# pixel_height, real_height_cm
|
| 52 |
-
# ) + convert_to_real_measurements(
|
| 53 |
-
# euclidean_distance((right_elbow.x, right_elbow.y), (right_wrist.x, right_wrist.y)),
|
| 54 |
-
# pixel_height, real_height_cm
|
| 55 |
-
# )
|
| 56 |
-
|
| 57 |
-
# leg_length_cm = convert_to_real_measurements(
|
| 58 |
-
# euclidean_distance((left_hip.x, left_hip.y), (left_knee.x, left_knee.y)),
|
| 59 |
-
# pixel_height, real_height_cm
|
| 60 |
-
# ) + convert_to_real_measurements(
|
| 61 |
-
# euclidean_distance((left_knee.x, left_knee.y), (left_ankle.x, left_ankle.y)),
|
| 62 |
-
# pixel_height, real_height_cm
|
| 63 |
-
# )
|
| 64 |
-
|
| 65 |
arm_length_cm = convert_to_real_measurements(
|
| 66 |
-
euclidean_distance((
|
| 67 |
pixel_height, real_height_cm
|
| 68 |
-
)
|
|
|
|
|
|
|
|
|
|
| 69 |
|
| 70 |
leg_length_cm = convert_to_real_measurements(
|
| 71 |
-
euclidean_distance((left_hip.x, left_hip.y), (
|
|
|
|
|
|
|
|
|
|
| 72 |
pixel_height, real_height_cm
|
| 73 |
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 74 |
|
| 75 |
shoulder_to_waist_cm = convert_to_real_measurements(
|
| 76 |
euclidean_distance((left_shoulder.x, left_shoulder.y), (left_hip.x, left_hip.y)),
|
|
@@ -78,21 +78,27 @@ def measure_body_sizes(side_colored_mask, front_colored_mask, sideposes, frontpo
|
|
| 78 |
)
|
| 79 |
|
| 80 |
# Calculate waist circumference using the ellipse circumference formula
|
|
|
|
| 81 |
a = euclidean_distance((left_hip.x, left_hip.y), (right_hip.x, right_hip.y)) / 2
|
| 82 |
-
|
|
|
|
|
|
|
| 83 |
|
| 84 |
# Use Ramanujan's approximation for the circumference of an ellipse
|
| 85 |
-
|
| 86 |
-
|
|
|
|
|
|
|
|
|
|
| 87 |
|
| 88 |
|
| 89 |
# Convert pixel measurements to real measurements using the height ratio
|
| 90 |
measurements.append({
|
| 91 |
-
"
|
| 92 |
-
"leg_length_cm": leg_length_cm,
|
| 93 |
"arm_length_cm": arm_length_cm,
|
|
|
|
| 94 |
"shoulder_to_waist_cm": shoulder_to_waist_cm,
|
| 95 |
-
"
|
| 96 |
"waist_circumference_cm": waist_circumference_cm
|
| 97 |
})
|
| 98 |
|
|
|
|
| 46 |
pixel_height, real_height_cm
|
| 47 |
)
|
| 48 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 49 |
arm_length_cm = convert_to_real_measurements(
|
| 50 |
+
euclidean_distance((right_shoulder.x, right_shoulder.y), (right_elbow.x, right_elbow.y)),
|
| 51 |
pixel_height, real_height_cm
|
| 52 |
+
) + convert_to_real_measurements(
|
| 53 |
+
euclidean_distance((right_elbow.x, right_elbow.y), (right_wrist.x, right_wrist.y)),
|
| 54 |
+
pixel_height, real_height_cm
|
| 55 |
+
)
|
| 56 |
|
| 57 |
leg_length_cm = convert_to_real_measurements(
|
| 58 |
+
euclidean_distance((left_hip.x, left_hip.y), (left_knee.x, left_knee.y)),
|
| 59 |
+
pixel_height, real_height_cm
|
| 60 |
+
) + convert_to_real_measurements(
|
| 61 |
+
euclidean_distance((left_knee.x, left_knee.y), (left_ankle.x, left_ankle.y)),
|
| 62 |
pixel_height, real_height_cm
|
| 63 |
)
|
| 64 |
+
|
| 65 |
+
# arm_length_cm = convert_to_real_measurements(
|
| 66 |
+
# euclidean_distance((left_shoulder.x, left_shoulder.y), (left_wrist.x, left_wrist.y)),
|
| 67 |
+
# pixel_height, real_height_cm
|
| 68 |
+
# )
|
| 69 |
+
|
| 70 |
+
# leg_length_cm = convert_to_real_measurements(
|
| 71 |
+
# euclidean_distance((left_hip.x, left_hip.y), (left_ankle.x, right_ankle.y)),
|
| 72 |
+
# pixel_height, real_height_cm
|
| 73 |
+
# )
|
| 74 |
|
| 75 |
shoulder_to_waist_cm = convert_to_real_measurements(
|
| 76 |
euclidean_distance((left_shoulder.x, left_shoulder.y), (left_hip.x, left_hip.y)),
|
|
|
|
| 78 |
)
|
| 79 |
|
| 80 |
# Calculate waist circumference using the ellipse circumference formula
|
| 81 |
+
# Calculate waist circumference using the ellipse circumference formula
|
| 82 |
a = euclidean_distance((left_hip.x, left_hip.y), (right_hip.x, right_hip.y)) / 2
|
| 83 |
+
|
| 84 |
+
# The semi-minor axis (b) can be estimated using a vertical distance, such as from the left hip to the left shoulder
|
| 85 |
+
b = euclidean_distance((left_hip.x, left_hip.y), (left_shoulder.x, left_shoulder.y)) / 2
|
| 86 |
|
| 87 |
# Use Ramanujan's approximation for the circumference of an ellipse
|
| 88 |
+
waist_circumference_px = math.pi * (3 * (a + b) - math.sqrt((3 * a + b) * (a + 3 * b)))
|
| 89 |
+
|
| 90 |
+
# Convert the waist circumference from pixel measurements to real measurements
|
| 91 |
+
waist_circumference_cm = convert_to_real_measurements(waist_circumference_px, pixel_height, real_height_cm)
|
| 92 |
+
|
| 93 |
|
| 94 |
|
| 95 |
# Convert pixel measurements to real measurements using the height ratio
|
| 96 |
measurements.append({
|
| 97 |
+
"height_cm": real_height_cm,
|
|
|
|
| 98 |
"arm_length_cm": arm_length_cm,
|
| 99 |
+
"shoulder_width_cm": shoulder_width_cm,
|
| 100 |
"shoulder_to_waist_cm": shoulder_to_waist_cm,
|
| 101 |
+
"leg_length_cm": leg_length_cm,
|
| 102 |
"waist_circumference_cm": waist_circumference_cm
|
| 103 |
})
|
| 104 |
|