2021-01-03 13:33:47 +01:00
|
|
|
from math import sqrt
|
|
|
|
|
2021-01-07 22:13:39 +01:00
|
|
|
|
2021-01-03 13:33:47 +01:00
|
|
|
def calculate_distance(ax, ay, bx, by):
|
|
|
|
distance = sqrt(((bx - ax) ** 2 + (by - ay) ** 2))
|
|
|
|
return distance
|
|
|
|
|
2021-01-07 22:13:39 +01:00
|
|
|
|
2021-01-03 13:33:47 +01:00
|
|
|
def check_index_finger(hand_landmarks):
|
2021-01-07 22:13:39 +01:00
|
|
|
return check_finger(hand_landmarks, 8, 5, 'wskazujacy')
|
2021-01-03 13:33:47 +01:00
|
|
|
|
|
|
|
|
|
|
|
def check_middle_finger(hand_landmarks):
|
2021-01-07 22:13:39 +01:00
|
|
|
return check_finger(hand_landmarks, 12, 9, 'srodkowy')
|
2021-01-03 13:33:47 +01:00
|
|
|
|
|
|
|
|
|
|
|
def check_ring_finger(hand_landmarks):
|
2021-01-07 22:13:39 +01:00
|
|
|
return check_finger(hand_landmarks, 16, 13, 'serdeczny')
|
2021-01-03 13:33:47 +01:00
|
|
|
|
|
|
|
|
|
|
|
def check_pinky_finger(hand_landmarks):
|
2021-01-07 22:13:39 +01:00
|
|
|
return check_finger(hand_landmarks, 20, 17, 'maly')
|
|
|
|
|
|
|
|
|
|
|
|
def check_finger(hand_landmarks, top_idx, bottom_idx, name):
|
|
|
|
ax = hand_landmarks.landmark[top_idx].x
|
|
|
|
ay = hand_landmarks.landmark[top_idx].y
|
|
|
|
bx = hand_landmarks.landmark[bottom_idx].x
|
|
|
|
by = hand_landmarks.landmark[bottom_idx].y
|
|
|
|
distance_top_bottom = calculate_distance(ax, ay, bx, by)
|
|
|
|
ax = hand_landmarks.landmark[bottom_idx].x
|
|
|
|
ay = hand_landmarks.landmark[bottom_idx].y
|
2021-01-03 13:33:47 +01:00
|
|
|
bx = hand_landmarks.landmark[0].x
|
|
|
|
by = hand_landmarks.landmark[0].y
|
2021-01-07 22:13:39 +01:00
|
|
|
distance_bottom_start = calculate_distance(ax, ay, bx, by)
|
2021-01-03 13:33:47 +01:00
|
|
|
|
2021-01-07 22:13:39 +01:00
|
|
|
if distance_bottom_start < distance_top_bottom + 0.1:
|
|
|
|
result = name + '_wyprostowany'
|
2021-01-03 13:33:47 +01:00
|
|
|
else:
|
2021-01-07 22:13:39 +01:00
|
|
|
result = name + '_niewyprostowany'
|
|
|
|
return result, hand_landmarks.landmark[top_idx].x, hand_landmarks.landmark[top_idx].y
|