-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_system.py
More file actions
279 lines (226 loc) · 8.82 KB
/
test_system.py
File metadata and controls
279 lines (226 loc) · 8.82 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
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
#!/usr/bin/env python3
"""
================================================================
System Test Script for Military-Grade Hand Gesture Control System
================================================================
Quick system validation and compatibility testing script.
Tests all major components before running the main system.
Author: Muhammad Kashan Tariq
Version: 1.0.0
================================================================
"""
import sys
import time
import traceback
def test_imports():
"""Test all required imports and report versions."""
print("🔍 Testing Python library imports...")
try:
import cv2
print(f"✅ OpenCV: {cv2.__version__}")
except ImportError as e:
print(f"❌ OpenCV: Failed to import - {e}")
return False
try:
import mediapipe as mp
print(f"✅ MediaPipe: {mp.__version__}")
except ImportError as e:
print(f"❌ MediaPipe: Failed to import - {e}")
return False
try:
import numpy as np
print(f"✅ NumPy: {np.__version__}")
except ImportError as e:
print(f"❌ NumPy: Failed to import - {e}")
return False
try:
import pynput
print(f"✅ PyInput: Available")
except ImportError as e:
print(f"❌ PyInput: Failed to import - {e}")
return False
try:
import torch
print(f"✅ PyTorch: {torch.__version__}")
if torch.cuda.is_available():
print(f"✅ CUDA: {torch.cuda.get_device_name(0)}")
else:
print("⚠️ CUDA: Not available")
except ImportError as e:
print(f"⚠️ PyTorch: Not available - {e}")
try:
import psutil
print(f"✅ PSUtil: Available")
except ImportError as e:
print(f"⚠️ PSUtil: Not available - {e}")
return True
def test_mediapipe_compatibility():
"""Test MediaPipe Hands initialization with version compatibility."""
print("\n🤖 Testing MediaPipe Hands compatibility...")
try:
import mediapipe as mp
import numpy as np
mp_hands = mp.solutions.hands
# Test configuration with version compatibility
hands_config = {
'static_image_mode': False,
'max_num_hands': 2,
'min_detection_confidence': 0.7,
'min_tracking_confidence': 0.5
}
# Try with model_complexity first
try:
hands_config['model_complexity'] = 1
hands = mp_hands.Hands(**hands_config)
print("✅ MediaPipe Hands initialized WITH model_complexity")
except TypeError as e:
if 'model_complexity' in str(e):
# Remove model_complexity for newer versions
hands_config.pop('model_complexity', None)
hands = mp_hands.Hands(**hands_config)
print("✅ MediaPipe Hands initialized WITHOUT model_complexity (newer version)")
else:
raise e
# Test basic processing
test_frame = np.zeros((480, 640, 3), dtype=np.uint8)
results = hands.process(test_frame)
print("✅ MediaPipe processing test successful")
hands.close()
return True
except Exception as e:
print(f"❌ MediaPipe test failed: {e}")
traceback.print_exc()
return False
def test_camera_detection():
"""Test camera device detection."""
print("\n📹 Testing camera detection...")
try:
import cv2
import platform
available_cameras = []
# Test camera indices 0-3
for i in range(4):
try:
if platform.system() == "Windows":
cap = cv2.VideoCapture(i, cv2.CAP_DSHOW)
else:
cap = cv2.VideoCapture(i)
if cap.isOpened():
ret, frame = cap.read()
if ret and frame is not None:
available_cameras.append(i)
print(f"✅ Camera {i}: Available ({frame.shape[1]}x{frame.shape[0]})")
else:
print(f"⚠️ Camera {i}: Opens but cannot read frames")
else:
print(f"❌ Camera {i}: Cannot open")
cap.release()
except Exception as e:
print(f"❌ Camera {i}: Error - {e}")
if available_cameras:
print(f"✅ Found {len(available_cameras)} working cameras: {available_cameras}")
return True
else:
print("❌ No working cameras found")
return False
except Exception as e:
print(f"❌ Camera test failed: {e}")
return False
def test_input_simulation():
"""Test input simulation capabilities."""
print("\n🎮 Testing input simulation...")
try:
from pynput import keyboard
from pynput.keyboard import Key, KeyCode
# Test keyboard controller creation
kb_controller = keyboard.Controller()
print("✅ Keyboard controller created")
# Test key object creation
test_keys = {
'w': KeyCode.from_char('w'),
'space': Key.space,
'escape': Key.esc
}
for key_name, key_obj in test_keys.items():
print(f"✅ Key '{key_name}': {key_obj}")
print("✅ Input simulation test successful")
print("⚠️ Note: Actual key presses not tested to avoid interference")
return True
except Exception as e:
print(f"❌ Input simulation test failed: {e}")
return False
def test_configuration_system():
"""Test configuration loading and validation."""
print("\n🔧 Testing configuration system...")
try:
# Import the configuration manager from main
sys.path.insert(0, '/workspace')
from main import ConfigurationManager
# Test configuration creation
config = ConfigurationManager("test_config.json")
print("✅ Configuration manager created")
# Test configuration access
camera_width = config.get("camera.width", 1280)
fps_target = config.get("performance.max_fps", 60)
print(f"✅ Configuration access: camera width={camera_width}, fps={fps_target}")
return True
except Exception as e:
print(f"❌ Configuration test failed: {e}")
traceback.print_exc()
return False
def run_comprehensive_system_test():
"""Run comprehensive system test suite."""
print("🔬" * 30)
print("MILITARY-GRADE SYSTEM COMPATIBILITY TEST")
print("🔬" * 30)
print("Testing all components before main system launch...")
tests = [
("Library Imports", test_imports),
("MediaPipe Compatibility", test_mediapipe_compatibility),
("Camera Detection", test_camera_detection),
("Input Simulation", test_input_simulation),
("Configuration System", test_configuration_system)
]
passed_tests = 0
failed_tests = 0
for test_name, test_func in tests:
print(f"\n🧪 Running {test_name} test...")
try:
if test_func():
passed_tests += 1
print(f"✅ {test_name}: PASSED")
else:
failed_tests += 1
print(f"❌ {test_name}: FAILED")
except Exception as e:
failed_tests += 1
print(f"💥 {test_name}: CRASHED - {e}")
print("\n" + "🔬" * 30)
print("TEST RESULTS SUMMARY")
print("🔬" * 30)
print(f"✅ Passed: {passed_tests}/{len(tests)} tests")
print(f"❌ Failed: {failed_tests}/{len(tests)} tests")
if failed_tests == 0:
print("\n🎉 ALL TESTS PASSED!")
print("✅ System is ready for gesture control!")
print("🚀 You can now run: python main.py")
return True
else:
print(f"\n⚠️ {failed_tests} test(s) failed.")
print("❗ Please resolve issues before running the main system.")
if failed_tests <= 2:
print("🔧 Minor issues detected - system may still work with reduced functionality.")
else:
print("🚨 Major issues detected - system may not work properly.")
return False
if __name__ == "__main__":
"""Run the system test when executed directly."""
print(f"Python Version: {sys.version}")
print(f"Platform: {sys.platform}")
success = run_comprehensive_system_test()
if success:
print("\n🎮 Ready to start gesture control!")
sys.exit(0)
else:
print("\n🔧 Please fix issues and run test again.")
sys.exit(1)