360 lines
14 KiB
Python
360 lines
14 KiB
Python
#!/usr/bin/env python3
|
|
"""
|
|
Complete Smart Intersection Integration Validation
|
|
Tests all integrated smart-intersection functionality
|
|
"""
|
|
|
|
import sys
|
|
import os
|
|
import json
|
|
import numpy as np
|
|
from pathlib import Path
|
|
|
|
# Add the qt_app_pyside1 directory to the Python path
|
|
sys.path.insert(0, os.path.dirname(os.path.abspath(__file__)))
|
|
|
|
def test_complete_integration():
|
|
"""Test complete smart intersection integration"""
|
|
print("=" * 80)
|
|
print("COMPLETE SMART INTERSECTION INTEGRATION VALIDATION")
|
|
print("=" * 80)
|
|
|
|
test_results = {}
|
|
|
|
# Test 1: Enhanced Video Detection Tab
|
|
print("\n=== Testing Enhanced Video Detection Tab ===")
|
|
try:
|
|
from ui.video_detection_tab import VideoDetectionTab, SmartIntersectionOverlay, IntersectionROIWidget, MultiCameraView
|
|
|
|
# Test main video detection tab
|
|
video_tab = VideoDetectionTab()
|
|
print("✅ Enhanced VideoDetectionTab with smart intersection features")
|
|
|
|
# Test smart intersection overlay
|
|
overlay = SmartIntersectionOverlay()
|
|
test_data = {
|
|
'active_tracks': 5,
|
|
'roi_events': 3,
|
|
'cameras': {'north': 2, 'east': 1, 'south': 0, 'west': 2},
|
|
'analytics': {'crosswalk_events': 1, 'lane_events': 2, 'safety_events': 0}
|
|
}
|
|
overlay.update_smart_intersection(test_data)
|
|
print("✅ Smart Intersection overlay with real-time data updates")
|
|
|
|
# Test ROI widget
|
|
roi_widget = IntersectionROIWidget()
|
|
print("✅ Intersection ROI management widget")
|
|
|
|
# Test multi-camera view
|
|
multi_cam = MultiCameraView()
|
|
print("✅ Multi-camera intersection view")
|
|
|
|
# Test configuration loading
|
|
config = video_tab.get_smart_intersection_config()
|
|
print(f"✅ Smart intersection configuration loaded: {len(config)} settings")
|
|
|
|
test_results['enhanced_video_tab'] = "PASS"
|
|
|
|
except Exception as e:
|
|
print(f"❌ Enhanced video detection tab test failed: {e}")
|
|
test_results['enhanced_video_tab'] = "FAIL"
|
|
|
|
# Test 2: Smart Intersection Controller
|
|
print("\n=== Testing Smart Intersection Controller ===")
|
|
try:
|
|
from controllers.smart_intersection_controller import SmartIntersectionController
|
|
|
|
controller = SmartIntersectionController()
|
|
print("✅ Smart Intersection Controller initialized")
|
|
|
|
# Test configuration
|
|
config = controller._load_config()
|
|
scene_analytics = config.get('desktop_app_config', {}).get('scene_analytics', {})
|
|
print(f"✅ Configuration loaded: Multi-camera: {scene_analytics.get('enable_multi_camera')}")
|
|
print(f" ROI Analytics: {scene_analytics.get('enable_roi_analytics')}")
|
|
print(f" VLM Integration: {scene_analytics.get('enable_vlm_integration')}")
|
|
|
|
# Test mode toggles
|
|
controller.set_enabled(True)
|
|
controller.set_multi_camera_mode(True)
|
|
controller.set_scene_analytics(True)
|
|
print("✅ Smart intersection modes enabled")
|
|
|
|
# Test ROI configuration
|
|
roi_config = controller._load_roi_config()
|
|
rois = roi_config.get('rois', [])
|
|
print(f"✅ ROI configuration loaded: {len(rois)} regions")
|
|
|
|
for roi in rois[:3]: # Show first 3 ROIs
|
|
print(f" - {roi.get('name')}: {roi.get('type')} (Priority: {roi.get('priority')})")
|
|
|
|
# Test frame processing
|
|
test_frame = np.zeros((720, 1280, 3), dtype=np.uint8)
|
|
test_detections = [
|
|
{
|
|
'bbox': [100, 100, 80, 150],
|
|
'class_name': 'person',
|
|
'confidence': 0.85
|
|
},
|
|
{
|
|
'bbox': [300, 200, 120, 80],
|
|
'class_name': 'car',
|
|
'confidence': 0.92
|
|
}
|
|
]
|
|
|
|
frame_data = {
|
|
'frame': test_frame,
|
|
'detections': test_detections
|
|
}
|
|
|
|
controller.process_frame(frame_data)
|
|
print("✅ Frame processing with enhanced detections")
|
|
|
|
# Test analytics
|
|
analytics = controller.get_current_analytics()
|
|
print(f"✅ Analytics data: {analytics['total_objects']} objects, {analytics['roi_events']} ROI events")
|
|
|
|
# Test intersection status
|
|
status = controller.get_intersection_status()
|
|
print(f"✅ Intersection status: {len(status)} metrics")
|
|
print(f" - Enabled: {status['enabled']}")
|
|
print(f" - Multi-camera: {status['multi_camera_mode']}")
|
|
print(f" - ROI regions: {status['roi_regions_active']}")
|
|
|
|
test_results['smart_intersection_controller'] = "PASS"
|
|
|
|
except Exception as e:
|
|
print(f"❌ Smart Intersection Controller test failed: {e}")
|
|
import traceback
|
|
traceback.print_exc()
|
|
test_results['smart_intersection_controller'] = "FAIL"
|
|
|
|
# Test 3: Scene Analytics Integration
|
|
print("\n=== Testing Scene Analytics Integration ===")
|
|
try:
|
|
from utils.scene_analytics.scene_adapter import SceneAnalyticsAdapter, FPSCalculator, ObjectTracker, ROIAnalyzer
|
|
|
|
# Test scene adapter
|
|
adapter = SceneAnalyticsAdapter(camera_id="test_intersection_cam")
|
|
print("✅ Scene Analytics Adapter initialized")
|
|
|
|
# Test FPS calculator
|
|
fps_calc = FPSCalculator()
|
|
for i in range(10):
|
|
fps = fps_calc.update()
|
|
print(f"✅ FPS Calculator: {fps:.1f} FPS")
|
|
|
|
# Test object tracker
|
|
tracker_config = {'max_unreliable_frames': 10}
|
|
tracker = ObjectTracker(tracker_config)
|
|
print("✅ Object Tracker initialized")
|
|
|
|
# Test ROI analyzer
|
|
roi_analyzer = ROIAnalyzer()
|
|
roi_analyzer.add_roi('test_crosswalk', {
|
|
'type': 'rectangle',
|
|
'coordinates': {'x': 100, 'y': 100, 'width': 200, 'height': 150}
|
|
})
|
|
print("✅ ROI Analyzer with crosswalk region")
|
|
|
|
# Test processing
|
|
test_frame = np.zeros((720, 1280, 3), dtype=np.uint8)
|
|
test_detections = [
|
|
{
|
|
'bbox': [150, 150, 50, 100],
|
|
'class_name': 'person',
|
|
'confidence': 0.9
|
|
}
|
|
]
|
|
|
|
result = adapter.process_frame(test_frame, test_detections)
|
|
print(f"✅ Scene processing: {len(result.get('objects', []))} objects processed")
|
|
print(f" Processing time: {result.get('processing_time_ms', 0):.1f}ms")
|
|
|
|
# Test performance stats
|
|
perf_stats = adapter.get_performance_stats()
|
|
if perf_stats:
|
|
print(f"✅ Performance stats: {len(perf_stats)} metrics")
|
|
else:
|
|
print("✅ Performance stats initialized")
|
|
|
|
test_results['scene_analytics'] = "PASS"
|
|
|
|
except Exception as e:
|
|
print(f"❌ Scene analytics test failed: {e}")
|
|
test_results['scene_analytics'] = "FAIL"
|
|
|
|
# Test 4: Configuration Files Integration
|
|
print("\n=== Testing Configuration Files ===")
|
|
try:
|
|
# Test tracker configuration
|
|
tracker_config_path = Path("config/smart-intersection/tracker-config.json")
|
|
if tracker_config_path.exists():
|
|
with open(tracker_config_path, 'r') as f:
|
|
tracker_config = json.load(f)
|
|
|
|
desktop_config = tracker_config.get('desktop_integration', {})
|
|
print("✅ Tracker configuration loaded")
|
|
print(f" GPU acceleration: {desktop_config.get('gpu_acceleration')}")
|
|
print(f" Local processing: {desktop_config.get('local_processing_only')}")
|
|
print(f" ROI analytics: {desktop_config.get('roi_analytics', {}).get('crosswalk_monitoring')}")
|
|
else:
|
|
print("⚠️ Tracker configuration file not found")
|
|
|
|
# Test desktop configuration
|
|
desktop_config_path = Path("config/smart-intersection/desktop-config.json")
|
|
if desktop_config_path.exists():
|
|
with open(desktop_config_path, 'r') as f:
|
|
desktop_config = json.load(f)
|
|
|
|
app_config = desktop_config.get('desktop_app_config', {})
|
|
scene_analytics = app_config.get('scene_analytics', {})
|
|
print("✅ Desktop configuration loaded")
|
|
print(f" Multi-camera: {scene_analytics.get('enable_multi_camera')}")
|
|
print(f" ROI analytics: {scene_analytics.get('enable_roi_analytics')}")
|
|
print(f" VLM integration: {scene_analytics.get('enable_vlm_integration')}")
|
|
else:
|
|
print("⚠️ Desktop configuration file not found")
|
|
|
|
test_results['configuration_files'] = "PASS"
|
|
|
|
except Exception as e:
|
|
print(f"❌ Configuration files test failed: {e}")
|
|
test_results['configuration_files'] = "FAIL"
|
|
|
|
# Test 5: Documentation Integration
|
|
print("\n=== Testing Documentation ===")
|
|
try:
|
|
docs_path = Path("docs/user-guide")
|
|
doc_files = []
|
|
|
|
if docs_path.exists():
|
|
for doc_file in docs_path.glob("*.md"):
|
|
doc_files.append(doc_file.name)
|
|
with open(doc_file, 'r', encoding='utf-8') as f:
|
|
content = f.read()
|
|
if len(content) > 100: # Valid content
|
|
print(f"✅ Documentation: {doc_file.name} ({len(content)} chars)")
|
|
else:
|
|
print(f"⚠️ Documentation: {doc_file.name} (short content)")
|
|
|
|
if doc_files:
|
|
print(f"✅ Found {len(doc_files)} documentation files")
|
|
else:
|
|
print("⚠️ No documentation files found")
|
|
|
|
test_results['documentation'] = "PASS" if doc_files else "FAIL"
|
|
|
|
except Exception as e:
|
|
print(f"❌ Documentation test failed: {e}")
|
|
test_results['documentation'] = "FAIL"
|
|
|
|
# Test 6: OpenVINO Integration
|
|
print("\n=== Testing OpenVINO Integration ===")
|
|
try:
|
|
from openvino import Core
|
|
|
|
core = Core()
|
|
devices = core.available_devices
|
|
print(f"✅ OpenVINO Core initialized")
|
|
print(f" Available devices: {devices}")
|
|
|
|
# Check for GPU
|
|
gpu_devices = [d for d in devices if 'GPU' in d]
|
|
if gpu_devices:
|
|
gpu_info = core.get_property(gpu_devices[0], "FULL_DEVICE_NAME")
|
|
print(f"✅ GPU device found: {gpu_info}")
|
|
|
|
if "Arc" in gpu_info:
|
|
print("🎯 Intel Arc GPU detected - optimal for smart intersection analytics!")
|
|
else:
|
|
print("✅ GPU available for acceleration")
|
|
else:
|
|
print("⚠️ No GPU devices found")
|
|
|
|
test_results['openvino_integration'] = "PASS"
|
|
|
|
except Exception as e:
|
|
print(f"❌ OpenVINO integration test failed: {e}")
|
|
test_results['openvino_integration'] = "FAIL"
|
|
|
|
# Test 7: Signal Integration
|
|
print("\n=== Testing Signal Integration ===")
|
|
try:
|
|
from PySide6.QtCore import QCoreApplication
|
|
from PySide6.QtWidgets import QApplication
|
|
|
|
# Create minimal Qt application for signal testing
|
|
app = QCoreApplication.instance() or QCoreApplication([])
|
|
|
|
# Test video detection tab signals
|
|
from ui.video_detection_tab import VideoDetectionTab
|
|
video_tab = VideoDetectionTab()
|
|
|
|
signals_to_test = [
|
|
'smart_intersection_enabled',
|
|
'multi_camera_mode_enabled',
|
|
'roi_configuration_changed',
|
|
'scene_analytics_toggled'
|
|
]
|
|
|
|
signals_found = 0
|
|
for signal_name in signals_to_test:
|
|
if hasattr(video_tab, signal_name):
|
|
signals_found += 1
|
|
print(f"✅ Signal found: {signal_name}")
|
|
else:
|
|
print(f"❌ Signal missing: {signal_name}")
|
|
|
|
print(f"✅ Signal integration: {signals_found}/{len(signals_to_test)} signals available")
|
|
|
|
test_results['signal_integration'] = "PASS" if signals_found == len(signals_to_test) else "PARTIAL"
|
|
|
|
except Exception as e:
|
|
print(f"❌ Signal integration test failed: {e}")
|
|
test_results['signal_integration'] = "FAIL"
|
|
|
|
# Test Summary
|
|
print("\n" + "=" * 80)
|
|
print("COMPLETE INTEGRATION TEST SUMMARY")
|
|
print("=" * 80)
|
|
|
|
total_tests = len(test_results)
|
|
passed_tests = len([r for r in test_results.values() if r == "PASS"])
|
|
partial_tests = len([r for r in test_results.values() if r == "PARTIAL"])
|
|
failed_tests = len([r for r in test_results.values() if r == "FAIL"])
|
|
|
|
for test_name, result in test_results.items():
|
|
status_icon = "✅" if result == "PASS" else "⚠️" if result == "PARTIAL" else "❌"
|
|
print(f"{status_icon} {test_name.replace('_', ' ').title():<30} {result}")
|
|
|
|
print("\n" + "-" * 80)
|
|
print(f"Total Tests: {total_tests}")
|
|
print(f"✅ Passed: {passed_tests}")
|
|
if partial_tests > 0:
|
|
print(f"⚠️ Partial: {partial_tests}")
|
|
if failed_tests > 0:
|
|
print(f"❌ Failed: {failed_tests}")
|
|
|
|
success_rate = (passed_tests + partial_tests * 0.5) / total_tests * 100
|
|
print(f"\nOverall Success Rate: {success_rate:.1f}%")
|
|
|
|
if success_rate >= 80:
|
|
print("\n🎉 EXCELLENT! Smart Intersection integration is highly successful!")
|
|
print("🚦 Multi-camera intersection analytics fully integrated")
|
|
print("📊 Scene-based analytics with ROI detection active")
|
|
print("⚡ Intel Arc GPU acceleration ready")
|
|
print("🎯 Real-time traffic monitoring and safety analysis enabled")
|
|
elif success_rate >= 60:
|
|
print("\n✅ GOOD! Smart Intersection integration is mostly successful!")
|
|
print("🔧 Some components may need minor adjustments")
|
|
else:
|
|
print("\n⚠️ Smart Intersection integration needs attention")
|
|
print("🛠️ Please check failed components")
|
|
|
|
return test_results
|
|
|
|
if __name__ == "__main__":
|
|
test_complete_integration()
|