|
import math |
|
import numpy as np |
|
import matplotlib.pyplot as plt |
|
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): |
|
"""Measure various body sizes based on detected poses.""" |
|
measurements = [] |
|
|
|
for pose in frontposes: |
|
|
|
keypoints = pose[0] |
|
|
|
|
|
left_eye = keypoints[1].position |
|
right_eye = keypoints[2].position |
|
nose = keypoints[3].position |
|
right_ear = keypoints[4].position |
|
left_shoulder = keypoints[5].position |
|
right_shoulder = keypoints[6].position |
|
left_elbow = keypoints[7].position |
|
right_elbow = keypoints[8].position |
|
left_wrist = keypoints[9].position |
|
right_wrist = keypoints[10].position |
|
left_hip = keypoints[11].position |
|
right_hip = keypoints[12].position |
|
left_knee = keypoints[13].position |
|
right_knee = keypoints[14].position |
|
left_ankle = keypoints[15].position |
|
right_ankle = keypoints[16].position |
|
|
|
|
|
pixel_height = euclidean_distance((left_eye.x, left_eye.y), (left_ankle.x, left_ankle.y)) |
|
|
|
|
|
shoulder_width_cm = convert_to_real_measurements( |
|
euclidean_distance((left_shoulder.x, left_shoulder.y),(right_shoulder.x, right_shoulder.y)), |
|
pixel_height, real_height_cm |
|
) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
arm_length_cm = convert_to_real_measurements( |
|
euclidean_distance((left_shoulder.x, left_shoulder.y), (left_wrist.x, left_wrist.y)), |
|
pixel_height, real_height_cm |
|
) |
|
|
|
leg_length_cm = convert_to_real_measurements( |
|
euclidean_distance((left_hip.x, left_hip.y), (left_ankle.x, right_ankle.y)), |
|
pixel_height, real_height_cm |
|
) |
|
|
|
shoulder_to_waist_cm = convert_to_real_measurements( |
|
euclidean_distance((left_shoulder.x, left_shoulder.y), (left_hip.x, left_hip.y)), |
|
pixel_height, real_height_cm |
|
) |
|
|
|
|
|
a = euclidean_distance((left_hip.x, left_hip.y), (right_hip.x, right_hip.y)) / 2 |
|
|
|
|
|
|
|
|
|
waist_circumference_cm = 90 |
|
|
|
|
|
|
|
measurements.append({ |
|
"shoulder_width_cm": shoulder_width_cm, |
|
"leg_length_cm": leg_length_cm, |
|
"arm_length_cm": arm_length_cm, |
|
"shoulder_to_waist_cm": shoulder_to_waist_cm, |
|
"height_cm": real_height_cm, |
|
"waist_circumference_cm": waist_circumference_cm |
|
}) |
|
|
|
return measurements |
|
|