#pragma once #include #include #include #include #include #include "frame/frame.h" #include "utils/simple_json.h" namespace rk3588 { struct RoiRect { float x = 0.0f; float y = 0.0f; float w = 1.0f; float h = 1.0f; }; struct AlarmRule { std::string name; std::set class_ids; RoiRect roi; int min_duration_ms = 0; int cooldown_ms = 5000; std::string schedule; // "HH:MM-HH:MM" format, empty = always active }; struct RuleMatchResult { bool matched = false; std::string rule_name; std::vector matched_detections; }; class RuleEngine { public: bool Init(const SimpleJson& rules_config, const std::vector& labels); RuleMatchResult Evaluate(const std::shared_ptr& frame); void Reset(); private: bool IsInRoi(const Rect& bbox, const RoiRect& roi, int img_w, int img_h) const; bool IsInSchedule(const std::string& schedule) const; bool CheckDuration(const std::string& rule_name, bool currently_matched); bool CheckCooldown(const std::string& rule_name); void TriggerCooldown(const std::string& rule_name); std::vector rules_; std::vector labels_; // Duration tracking: rule_name -> first match time std::map duration_start_; // Cooldown tracking: rule_name -> last trigger time std::map last_trigger_; }; } // namespace rk3588