-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_navigation.py
More file actions
148 lines (114 loc) Β· 4.78 KB
/
test_navigation.py
File metadata and controls
148 lines (114 loc) Β· 4.78 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
"""
Simple test for the blind navigation assistant.
"""
import cv2
import numpy as np
from blind_navigation_assistant import NavigationAssistant, BlindNavigationApp
def test_navigation_audio():
"""Test the navigation assistant audio system."""
print("π― Testing Navigation Assistant Audio System")
print("=" * 50)
# Initialize navigation assistant
nav_assistant = NavigationAssistant()
# Test TTS system
if nav_assistant.tts_engine:
print("β
Text-to-speech system initialized")
print("π Testing audio feedback...")
# Test basic announcement
nav_assistant._speak_message("Navigation assistant ready")
# Test navigation feedback
test_messages = [
"Red circle directly ahead",
"Blue rectangle on the left",
"Path ahead is clear",
"CAUTION: Obstacle directly ahead"
]
for i, message in enumerate(test_messages):
print(f"π Playing message {i+1}: {message}")
nav_assistant._speak_message(message)
import time
time.sleep(2) # Pause between messages
print("β
Audio test completed")
else:
print("β Text-to-speech not available")
return nav_assistant.tts_engine is not None
def test_zone_detection():
"""Test zone-based object detection."""
print("\nπ― Testing Zone-based Detection")
print("=" * 50)
# Create test navigation assistant
nav_assistant = NavigationAssistant()
# Create mock detection result with objects in different zones
from models import DetectedObject, BoundingBox, Color, Shape, DetectionResult
# Create test objects
test_objects = [
# Object in immediate center (critical zone)
DetectedObject(
bounding_box=BoundingBox(300, 400, 80, 60),
contour=np.array([[300, 400], [380, 400], [380, 460], [300, 460]]),
color=Color(255, 0, 0, "red", 0.9),
shape=Shape("rectangle", 0.8, 4, 0.85, 1.33)
),
# Object in immediate left (high priority)
DetectedObject(
bounding_box=BoundingBox(100, 350, 60, 60),
contour=np.array([[100, 350], [160, 350], [160, 410], [100, 410]]),
color=Color(0, 255, 0, "green", 0.95),
shape=Shape("square", 0.95, 4, 0.9, 1.0)
),
# Object in far right (medium priority)
DetectedObject(
bounding_box=BoundingBox(500, 200, 70, 50),
contour=np.array([[500, 200], [570, 200], [570, 250], [500, 250]]),
color=Color(0, 0, 255, "blue", 0.85),
shape=Shape("rectangle", 0.75, 4, 0.8, 1.4)
)
]
# Create mock frame
test_frame = np.zeros((480, 640, 3), dtype=np.uint8)
# Create detection result
detection_result = DetectionResult(
objects=test_objects,
frame=test_frame,
timestamp=1234567890.0
)
# Analyze scene
analysis = nav_assistant.analyze_scene(detection_result)
print(f"π Analysis Results:")
print(f" Total objects: {analysis['total_objects']}")
print(f" Zones with objects: {len(analysis['zone_analysis'])}")
for zone, zone_data in analysis['zone_analysis'].items():
print(f" {zone}: {zone_data['object_count']} objects ({zone_data['priority']} priority)")
print(f"\nπ§ Navigation Advice:")
for advice in analysis['navigation_advice']:
print(f" β’ {advice}")
print(f"\nβ οΈ Warnings:")
for warning in analysis['warnings']:
print(f" β’ {warning}")
# Test audio feedback
if nav_assistant.tts_engine:
print(f"\nπ Providing audio feedback...")
nav_assistant.provide_audio_feedback(analysis)
return True
def main():
"""Main test function."""
print("π― Blind Navigation Assistant - Test Suite")
print("=" * 60)
# Test 1: Audio system
audio_success = test_navigation_audio()
# Test 2: Zone detection
zone_success = test_zone_detection()
print(f"\nπ Test Results:")
print(f" Audio System: {'β
PASS' if audio_success else 'β FAIL'}")
print(f" Zone Detection: {'β
PASS' if zone_success else 'β FAIL'}")
if audio_success and zone_success:
print(f"\nπ All tests passed! Ready to run full navigation assistant.")
response = input(f"\nWould you like to run the full navigation assistant? (y/n): ")
if response.lower() in ['y', 'yes']:
print(f"\nπ Starting Blind Navigation Assistant...")
app = BlindNavigationApp()
app.run()
else:
print(f"\nβ οΈ Some tests failed. Please check the system.")
if __name__ == "__main__":
main()