-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathadas_fast.py
More file actions
executable file
·166 lines (133 loc) · 5.24 KB
/
adas_fast.py
File metadata and controls
executable file
·166 lines (133 loc) · 5.24 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
#!/usr/bin/env python3
"""
ADAS FAST - Performance-Optimized Version
Targets 25-30 FPS with essential features only
Run: python3 adas_fast.py
"""
import wx
import cv2
import numpy as np
import sys
import time
from pathlib import Path
from typing import List, Tuple, Optional, Dict
print("=" * 70)
print(" ADAS FAST - Performance Optimized")
print("=" * 70)
# Import base application
try:
import importlib.util
spec = importlib.util.spec_from_file_location("base_app", "adas-perception.py")
base_app = importlib.util.module_from_spec(spec)
spec.loader.exec_module(base_app)
print("✅ Base application loaded")
except Exception as e:
print(f"❌ Could not load base app: {e}")
sys.exit(1)
print("=" * 70)
class FastMainFrame(base_app.MainFrame):
"""Optimized main frame for maximum performance"""
def __init__(self):
# Initialize base class
super().__init__()
# Set title
self.SetTitle("ADAS FAST - Performance Optimized (30+ FPS)")
# PERFORMANCE SETTINGS - All heavy features disabled
self.fast_mode = True
self.frame_skip = 1 # Process every frame (no skipping for basic features)
self.frame_count = 0
# Override settings for performance
self.settings.update({
"enable_detection": True, # Keep
"enable_tracking": True, # Keep
"enable_lanes": True, # Keep
"confidence_threshold": 0.5, # Higher = fewer detections = faster
"ego_speed": 60,
})
print("\n" + "=" * 70)
print(" FAST MODE SETTINGS:")
print("=" * 70)
print(" ✅ Object Detection (YOLOv8)")
print(" ✅ Multi-Object Tracking")
print(" ✅ Lane Detection")
print(" ✅ Collision Warning")
print(" ✅ Distance Estimation")
print(" ❌ All advanced features DISABLED for speed")
print("=" * 70)
print("\n Target: 25-30 FPS")
print(" Recommended: 1 camera @ 640x480 or 1280x720")
print("=" * 70)
print("\n🚀 Application ready! Click START to begin.\n")
def _processing_loop(self):
"""Optimized processing loop - essential features only"""
while self.running:
try:
frames = self.camera_manager.get_all_frames()
if not frames:
time.sleep(0.001) # Minimal sleep
continue
self.frame_count += 1
primary_frame = frames.get(self.primary_camera)
if primary_frame is not None:
settings = self.settings.copy()
# Update perception engine
self.perception_engine.detector.confidence_threshold = settings["confidence_threshold"]
self.perception_engine.collision_system.set_ego_speed(settings["ego_speed"])
# CORE PROCESSING ONLY - No extras
result_frame, metrics = self.perception_engine.process_frame(
primary_frame,
enable_detection=settings["enable_detection"],
enable_lanes=settings["enable_lanes"],
enable_tracking=settings["enable_tracking"]
)
# NO ULTRA FEATURES - Maximum performance
# Record if active
if self.video_recorder.is_recording:
self.video_recorder.write_frame(result_frame)
# Create secondary frames dict (minimal processing)
secondary_frames = {}
camera_ids = sorted([k for k in frames.keys() if k != self.primary_camera])
# Show other cameras RAW (no processing)
for cam_id in camera_ids[:3]: # Max 3 secondary cameras
if cam_id in frames:
secondary_frames[cam_id] = frames[cam_id]
# Post update event
evt = base_app.FrameUpdateEvent(
primary_frame=result_frame,
secondary_frames=secondary_frames,
bev_frame=None
)
wx.PostEvent(self, evt)
# Post metrics
metrics_evt = base_app.MetricsUpdateEvent(metrics=metrics)
wx.PostEvent(self, metrics_evt)
except Exception as e:
import logging
logging.getLogger('ADAS').error(f"Processing error: {e}")
time.sleep(0.01)
def main():
"""Main entry point"""
print("\n" + "=" * 70)
print(" Starting ADAS FAST Application")
print("=" * 70)
# Create application
app = wx.App()
# Set dark theme
if hasattr(wx, 'SystemOptions'):
wx.SystemOptions.SetOption("msw.dark-mode", 2)
# Create and show frame
frame = FastMainFrame()
frame.Show()
frame.Center()
# Start main loop
app.MainLoop()
if __name__ == "__main__":
try:
main()
except KeyboardInterrupt:
print("\n\nShutdown requested...exiting")
except Exception as e:
print(f"\nFatal error: {e}")
import traceback
traceback.print_exc()
sys.exit(1)