#pragma once #include "frame/frame.h" #include namespace rk3588 { // 空间关系类型 enum class SpatialRelation { BELOW, // 目标在锚点下方 ABOVE, // 目标在锚点上方 INSIDE, // 目标在锚点内部 OVERLAP, // 目标与锚点重叠 NEAR // 目标在锚点附近 }; // 空间匹配配置 struct SpatialConfig { SpatialRelation relation = SpatialRelation::BELOW; float iou_threshold = 0.3f; // IOU阈值 float foot_ratio = 0.3f; // 脚下区域比例(人体高度) float expand_ratio = 1.0f; // 框扩大系数 float max_distance = 0.5f; // 最大归一化距离(NEAR模式用) }; // 匹配结果 struct SpatialMatchResult { bool matched = false; float iou = 0.0f; float distance = 0.0f; // 归一化距离 Rect foot_region; // 脚下区域(用于可视化) }; class SpatialMatcher { public: SpatialMatcher(const SpatialConfig& config); // 检查目标是否在锚点的指定空间位置 SpatialMatchResult Match(const Detection& anchor, const Detection& target, int img_w, int img_h); // 计算脚下区域 Rect CalculateFootRegion(const Rect& person_bbox, int img_w, int img_h); private: SpatialConfig config_; // 计算两个框的IOU float CalculateIoU(const Rect& a, const Rect& b); // 计算归一化中心点距离 float CalculateDistance(const Rect& anchor, const Rect& target, int img_w, int img_h); // 检查目标是否在锚点下方 bool IsBelow(const Rect& anchor, const Rect& target, int img_w, int img_h); }; } // namespace rk3588