PerceptionManager API¶
PerceptionManager handles sensor fusion and object detection using multi-view cameras, LiDAR, and
ML models (YOLOv8/YOLOv5).
| Component | Status | Purpose |
|---|---|---|
| Multi-Camera Array | ✅ Active | Front, left, right RGB cameras |
| LiDAR Sensor | ✅ Active | Distance filtering and validation |
| YOLOv8 Detection | 🔄 Updated | Primary ML model with YOLOv5 fallback |
| Traffic Light Detection | ✅ Active | Ground truth from CARLA server |
| Thread Safety | 🔧 Fixed | Robust cv2.waitKey error handling |
Sensor Configuration¶
What it manages: Multi-sensor setup with ML-based object detection
# Multi-view camera setup
self.rgb_camera = [
CameraSensor(vehicle,'front'),
CameraSensor(vehicle, 'right'),
CameraSensor(vehicle, 'left')
]
# LiDAR for distance validation
self.lidar = LidarSensor(vehicle, config['lidar'])
# Optional semantic LiDAR for data collection
if data_dump:
self.semantic_lidar = SemanticLidarSensor(vehicle, config['lidar'])
Detection Pipeline¶
What it does: Multi-modal object detection with ML models and sensor fusion
def activate_mode(self, objects):
# Process each camera view for camera in self.rgb_camera:
if camera.image is not None:
# YOLOv8/YOLOv5 inference
detections = self.ml_manager.object_detector(camera.image)
vehicles = self.process_detections(detections, camera)
objects['vehicles'].extend(vehicles)
# LiDAR distance filtering
objects['vehicles'] = self.lidar_filter(objects['vehicles'])
# Add traffic lights (ground truth)
objects = self.retrieve_traffic_lights(objects)
return objects
Detection Modes¶
What it supports: Flexible detection modes for different use cases
- Multi-Camera Fusion: Front, left, right camera processing
- YOLOv8/YOLOv5: Automatic model selection with fallback
- LiDAR Validation: Distance filtering and range checking
- Thread Safety: Robust error handling for concurrent access
- Use Case: Realistic ML-based perception for training/evaluation
- Perfect Accuracy: CARLA server ground truth
- Zero Latency: No ML inference overhead
- Debugging: Ideal for algorithm development
- Use Case: Baseline comparison, rapid prototyping
Set activate: true/false in YAML for ML vs ground truth mode
YOLOv8 Technical Details¶
What's new: Enhanced ML pipeline with automatic model selection and compatibility
def process_detections(self, results, camera):
if self.use_v8:
# Convert YOLOv8 → YOLOv5 format for compatibility
boxes = results[0].boxes
xyxy = boxes.xyxy.cpu()
conf = boxes.conf.cpu().unsqueeze(1)
cls = boxes.cls.cpu().unsqueeze(1)
detections = torch.cat([xyxy, conf, cls], dim=1)
else:
# YOLOv5 format already compatible
detections = results.xyxy[0].cpu()
return self.camera_lidar_fusion(detections, camera)
Integration Examples¶
Usage Patterns
Common ways to use PerceptionManager in scenarios:
# Create perception manager
perception_manager = PerceptionManager(
vehicle=carla_vehicle, config_yaml=config['sensing']['perception'], ml_manager=cav_world.ml_manager
)
# Detection in simulation loop
ego_pos = vehicle.get_transform()
detected_objects = perception_manager.detect(ego_pos)
# Process results
for vehicle_detection in detected_objects['vehicles']:
distance = vehicle_detection['distance']
confidence = vehicle_detection['confidence']
# Extend MLManager for custom detection class
class CustomMLManager(MLManager):
def __init__(self):
super().__init__()
self.custom_detector = load_custom_model()
def detect_custom_objects(self, image):
return self.custom_detector(image)
# Use with PerceptionManager
cav_world.ml_manager = CustomMLManager()
Related: