-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_setup.py
More file actions
151 lines (128 loc) · 4.84 KB
/
test_setup.py
File metadata and controls
151 lines (128 loc) · 4.84 KB
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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
import os
import sys
def test_imports():
"""Teste l'import des modules nécessaires"""
print("[TEST 1] Vérification des imports...")
try:
import cv2
print(" opencv-python")
import mediapipe as mp
print(" mediapipe")
import numpy as np
print(" numpy")
from mediapipe.tasks import python
print(" mediapipe.tasks")
print(" TOUS les imports réussis\n")
return True
except ImportError as e:
print(f" ERREUR: {e}\n")
return False
def test_models():
"""Teste la disponibilité des modèles"""
print("[TEST 2] Vérification des modèles MediaPipe...")
models = [
"hand_landmarker.task",
"gesture_recognizer.task",
]
all_exist = True
for model in models:
if os.path.exists(model):
print(f" {model}")
else:
print(f" {model} - MANQUANT")
all_exist = False
if not all_exist:
print(" \n Exécutez: python download_models.py\n")
else:
print(" Tous les modèles sont présents\n")
return all_exist
def test_webcam():
"""Teste si la webcam fonctionne"""
print("[TEST 3] Vérification de la webcam...")
try:
import cv2
cap = cv2.VideoCapture(0)
if cap.isOpened():
ret, frame = cap.read()
if ret:
print(f" Webcam détectée (résolution: {frame.shape[1]}x{frame.shape[0]})")
cap.release()
print(" Webcam fonctionnelle\n")
return True
else:
print(" Impossible de lire depuis la webcam\n")
cap.release()
return False
else:
print(" Webcam non détectée\n")
return False
except Exception as e:
print(f" ERREUR: {e}\n")
return False
def test_models_loading():
"""Teste le chargement des modèles MediaPipe"""
print("[TEST 4] Chargement des modèles MediaPipe...")
try:
import mediapipe as mp
from mediapipe.tasks import python
from mediapipe.tasks.python import vision
if os.path.exists("hand_landmarker.task"):
print(" Chargement de hand_landmarker...")
BaseOptions = mp.tasks.BaseOptions
HandLandmarker = mp.tasks.vision.HandLandmarker
HandLandmarkerOptions = mp.tasks.vision.HandLandmarkerOptions
options = HandLandmarkerOptions(
base_options=BaseOptions(model_asset_path="hand_landmarker.task"),
running_mode=mp.tasks.vision.RunningMode.IMAGE,
num_hands=1
)
with HandLandmarker.create_from_options(options) as landmarker:
print(" hand_landmarker chargé correctement")
if os.path.exists("gesture_recognizer.task"):
print(" Chargement de gesture_recognizer...")
GestureRecognizer = mp.tasks.vision.GestureRecognizer
GestureRecognizerOptions = mp.tasks.vision.GestureRecognizerOptions
options = GestureRecognizerOptions(
base_options=BaseOptions(model_asset_path="gesture_recognizer.task"),
running_mode=mp.tasks.vision.RunningMode.IMAGE,
num_hands=1
)
with GestureRecognizer.create_from_options(options) as recognizer:
print(" gesture_recognizer chargé correctement")
print(" TOUS les modèles se chargent correctement\n")
return True
except Exception as e:
print(f" ERREUR lors du chargement: {e}\n")
return False
def main():
print("=" * 60)
print("TEST D'INSTALLATION - Camera Project")
print("=" * 60 + "\n")
results = []
results.append(("Imports", test_imports()))
results.append(("Modèles disponibles", test_models()))
results.append(("Webcam", test_webcam()))
if results[1][1]:
results.append(("Chargement des modèles", test_models_loading()))
print("=" * 60)
print("RÉSUMÉ DES TESTS")
print("=" * 60)
passed = sum(1 for _, result in results if result)
total = len(results)
for name, result in results:
status = "PASS" if result else "FAIL"
print(f"{name}: {status}")
print(f"\nRésultat: {passed}/{total} tests réussis")
if passed == total:
print("\nLE PROJET EST PRÊT À ÊTRE UTILISÉ!")
print("\nLancez l'une de ces commandes:")
print(" - python cam.py")
print(" - python camera.py")
print(" - python signe.py")
return 0
else:
print("\nCERTAINS TESTS ONT ÉCHOUÉ")
print("\nVérifiez les instructions d'installation dans README.md")
return 1
if __name__ == "__main__":
sys.exit(main())