-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathLateralFlexionTest.py
100 lines (75 loc) · 3.96 KB
/
LateralFlexionTest.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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
import cv2
import mediapipe as mp
import numpy as np
import matplotlib.pyplot as plt
from Test import FlexionTest
class RightFlexionTest(FlexionTest):
def __init__(self):
super().__init__()
def process_video(self, video_path, envergure):
cap = cv2.VideoCapture(video_path)
if not cap.isOpened():
print("Erreur : impossible d'ouvrir la vidéo")
return
self.frame_count = 0
while cap.isOpened():
ret, frame = cap.read()
if not ret:
break
image = cv2.cvtColor(frame, cv2.COLOR_BGR2RGB)
image.flags.writeable = True
results = self.holistic.process(image)
width, height, _ = image.shape
if self.frame_count == 0 and results.left_hand_landmarks and results.right_hand_landmarks:
majeur_gauche = results.left_hand_landmarks.landmark[12]
majeur_droit = results.right_hand_landmarks.landmark[12]
conversion_factor = self.compute_conversion_factor(majeur_gauche, majeur_droit, envergure, width, height)
print(conversion_factor)
position_pied_droit_frame1 = results.pose_landmarks.landmark[self.mp_holistic.PoseLandmark.RIGHT_FOOT_INDEX]
if results.right_hand_landmarks:
majeur_droit = results.right_hand_landmarks.landmark[12]
y = int(majeur_droit.y * width)
cv2.line(image, (0, y), (frame.shape[1], y), (255, 0, 0), 2)
distance_pixels = np.sqrt((majeur_droit.y - position_pied_droit_frame1.y) ** 2)
distance_cm = distance_pixels * conversion_factor
self.distance_doigts_Pieds_cm.append(distance_cm)
self.positions_moyennes_majeurs.append(majeur_droit)
self.frame_count += 1
self.positions_moyennes_majeurs = [coord_frame.y for coord_frame in self.positions_moyennes_majeurs]
cap.release()
return self.distance_doigts_Pieds_cm, position_pied_droit_frame1.y, self.positions_moyennes_majeurs
class LeftFlexionTest(FlexionTest):
def __init__(self):
super().__init__()
def process_video(self, video_path, envergure):
cap = cv2.VideoCapture(video_path)
if not cap.isOpened():
print("Erreur : impossible d'ouvrir la vidéo")
return
self.frame_count = 0
while cap.isOpened():
ret, frame = cap.read()
if not ret:
break
image = cv2.cvtColor(frame, cv2.COLOR_BGR2RGB)
image.flags.writeable = True
results = self.holistic.process(image)
width, height, _ = image.shape
if self.frame_count == 0 and results.left_hand_landmarks and results.right_hand_landmarks:
majeur_gauche = results.left_hand_landmarks.landmark[12]
majeur_droit = results.right_hand_landmarks.landmark[12]
conversion_factor = self.compute_conversion_factor(majeur_gauche, majeur_droit, envergure, width, height)
print(conversion_factor)
position_pied_gauche_frame1 = results.pose_landmarks.landmark[self.mp_holistic.PoseLandmark.LEFT_FOOT_INDEX]
if results.left_hand_landmarks:
majeur_gauche = results.left_hand_landmarks.landmark[12]
distance_pixels = np.sqrt((majeur_gauche.y - position_pied_gauche_frame1.y) ** 2)
print(distance_pixels)
distance_cm = (distance_pixels * conversion_factor) - 1
print(distance_cm)
self.distance_doigts_Pieds_cm.append(distance_cm)
self.positions_moyennes_majeurs.append(majeur_gauche)
self.frame_count += 1
self.positions_moyennes_majeurs = [coord_frame.y for coord_frame in self.positions_moyennes_majeurs]
cap.release()
return self.distance_doigts_Pieds_cm, position_pied_gauche_frame1.y, self.positions_moyennes_majeurs