# 流星探测器接口与并行管道 本文档描述了流星探测系统中的探测器抽象和并行处理管道。 ## 探测器接口 所有流星探测器实现一个统一的接口 `MeteorDetector`,这使得它们可以互相替换或者同时使用。 ```rust pub trait MeteorDetector: Send + Sync { // 处理单帧图像,返回探测结果 fn process_frame(&mut self, frame: &core::Mat, frame_index: u64) -> Result; // 重置探测器状态 fn reset(&mut self); // 获取探测器的配置 fn get_config(&self) -> DetectorConfig; // 获取探测器的唯一标识符 fn get_id(&self) -> &str; } ``` ### 内置探测器 系统目前提供两种探测器实现: 1. **BrightnessDetector**:基于帧间亮度对比的探测器,适合检测较快的、亮度变化明显的流星。 2. **CamsDetector**:基于CAMS FTP格式的探测器,使用256帧的统计特征(maxpixel、avepixel、stdpixel、maxframe)来检测流星。 ### 探测器配置 探测器通过枚举类型 `DetectorConfig` 进行配置: ```rust pub enum DetectorConfig { Brightness(BrightnessDetectorParams), Cams(CamsDetectorParams), } ``` 每种探测器都有各自的参数结构体,包含调整其行为的各种参数。 ## 并行探测管道 `DetectionPipeline` 提供了一个并行执行多个探测器的框架,它能够: 1. 同时运行多个探测器检测同一帧图像 2. 聚合多个探测器的结果 3. 根据聚合策略决定最终探测结果 ### 管道配置 ```rust pub struct PipelineConfig { // 要使用的探测器列表 pub detectors: Vec, // 最大并行工作线程数 pub max_parallel_workers: usize, // 事件缓冲时间(秒) pub event_buffer_seconds: u32, // 结果聚合策略 pub aggregation_strategy: AggregationStrategy, } ``` ### 聚合策略 系统支持多种聚合策略,用于从多个探测器的结果中得出最终结论: ```rust pub enum AggregationStrategy { // 任何探测器报告检测都视为有效 Any, // 所有探测器都必须报告检测才视为有效 All, // 多数探测器报告检测才视为有效 Majority, // 自定义阈值:例如 Threshold(0.6) 表示至少 60% 的探测器报告检测 Threshold(f32), } ``` ## 使用示例 ### 创建单个探测器 ```rust // 使用默认参数创建亮度探测器 let brightness_detector = BrightnessDetector::new(); // 使用自定义参数创建CAMS探测器 let params = CamsDetectorParams { brightness_threshold: 30, std_to_avg_ratio_threshold: 1.5, min_pixel_count: 10, min_trajectory_length: 5, save_all_feature_images: false, output_dir: PathBuf::from("output"), file_prefix: "meteor".to_string(), id: "cams-1".to_string(), }; let cams_detector = CamsDetector::with_params(params); ``` ### 创建并行管道 ```rust // 定义两个探测器的配置 let detector_configs = vec![ DetectorConfig::Brightness(BrightnessDetectorParams::default()), DetectorConfig::Cams(CamsDetectorParams::default()), ]; // 创建管道配置 let pipeline_config = PipelineConfig { detectors: detector_configs, max_parallel_workers: 4, event_buffer_seconds: 10, aggregation_strategy: AggregationStrategy::Any, }; // 创建探测管道 let pipeline = DetectionPipeline::new( camera_controller, &config, Some(pipeline_config), )?; // 启动管道 pipeline.run().await?; ``` ### 在配置文件中定义 在 `config.toml` 中可以定义整个探测管道: ```toml [detection] min_brightness_delta = 30.0 min_pixel_change = 10 min_frames = 3 event_buffer_seconds = 10 sensitivity = 0.7 [detection.pipeline] max_parallel_workers = 4 aggregation_strategy = "any" # 可以是 "any", "all", "majority" [[detection.pipeline.detectors]] type = "brightness" min_brightness_delta = 30.0 min_pixel_change = 10 min_frames = 3 sensitivity = 0.7 id = "brightness-1" [[detection.pipeline.detectors]] type = "cams" brightness_threshold = 30 std_to_avg_ratio_threshold = 1.5 min_pixel_count = 10 min_trajectory_length = 5 save_all_feature_images = false output_dir = "output/cams" file_prefix = "meteor" id = "cams-1" ``` ## 性能考量 - 并行执行可以提高处理速度,但也会增加内存和CPU使用 - 对于资源受限的设备(如树莓派),应考虑减少并行探测器数量或使用顺序执行 - 某些探测器(如CamsDetector)可能需要积累多帧才能完成检测 ## 扩展 要添加新的探测器类型: 1. 创建一个新的结构体并实现 `MeteorDetector` trait 2. 在 `DetectorConfig` 枚举中添加新的变体 3. 更新 `DetectorFactory::create()` 方法以支持创建新的探测器