-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdetermine_leading_and_trailing_ankle.py
77 lines (50 loc) · 3.71 KB
/
determine_leading_and_trailing_ankle.py
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
def determine_leading_and_trailing_ankle(keypoints_with_scores,
KEYPOINT_DICT,
running_direction,
leading_ankle_x_max_value_all_images,
trailing_ankle_x_min_value_all_images):
left_ankle = KEYPOINT_DICT['left_ankle']
right_ankle = KEYPOINT_DICT['right_ankle']
left_ankle_x_value = keypoints_with_scores[0][0][left_ankle][1] # X-axis value of left knee. (Origin: Top left)
right_ankle_x_value = keypoints_with_scores[0][0][right_ankle][1] # X-axis value of right knee. (Origin: Top left)
# If runner runs towards the RIGHT SIDE of the image, the leading ankle is determined by max().
if running_direction == "right":
# ------------ Leading ankle ------------
# Determine x value of leading ankle.
leading_ankle_x_value = max(left_ankle_x_value, right_ankle_x_value)
# At the start, there is no value assigned to this variable, therefore we set an initial value.
if leading_ankle_x_max_value_all_images == None:
leading_ankle_x_max_value_all_images = leading_ankle_x_value
# If the x value of the current leading ankle reaches a new extreme value, overwrite the previous value.
if leading_ankle_x_value > leading_ankle_x_max_value_all_images:
leading_ankle_x_max_value_all_images = leading_ankle_x_value
# ------------ Trailing ankle ------------
# Determine x value of trailing ankle.
trailing_ankle_x_value = min(left_ankle_x_value, right_ankle_x_value)
# At the start, there is no value assigned to this variable, therefore we set an initial value.
if trailing_ankle_x_min_value_all_images == None:
trailing_ankle_x_min_value_all_images = trailing_ankle_x_value
# If the x value of the current trailing ankle reaches a new extreme value, overwrite the previous value.
if trailing_ankle_x_value < trailing_ankle_x_min_value_all_images:
trailing_ankle_x_min_value_all_images = trailing_ankle_x_value
# If runner runs towards the LEFT SIDE of the image, the leading ankle is determined by min().
elif running_direction == "left":
# ------------ Leading ankle ------------
# Determine x value of leading ankle.
leading_ankle_x_value = min(left_ankle_x_value, right_ankle_x_value)
# At the start, there is no value assigned to this variable, therefore we set an initial value.
if leading_ankle_x_max_value_all_images == None:
leading_ankle_x_max_value_all_images = leading_ankle_x_value
# If the x value of the current leading ankle reaches a new extreme value, overwrite the previous value.
if leading_ankle_x_value < leading_ankle_x_max_value_all_images:
leading_ankle_x_max_value_all_images = leading_ankle_x_value
# ------------ Trailing ankle ------------
# Determine x value of trailing ankle.
trailing_ankle_x_value = max(left_ankle_x_value, right_ankle_x_value)
# At the start, there is no value assigned to this variable, therefore we set an initial value.
if trailing_ankle_x_min_value_all_images == None:
trailing_ankle_x_min_value_all_images = trailing_ankle_x_value
# If the x value of the current leading ankle reaches a new extreme value, overwrite the previous value.
if trailing_ankle_x_value > trailing_ankle_x_min_value_all_images:
trailing_ankle_x_min_value_all_images = trailing_ankle_x_value
return leading_ankle_x_value, trailing_ankle_x_value, leading_ankle_x_max_value_all_images, trailing_ankle_x_min_value_all_images