safesight/edge/plugins/logic_gate/spatial_matcher.h
tian 29d9ef5d0d refactor: 项目结构梳理 - 设备端/管理端对称布局
仓库结构:
  edge/     设备端(原根目录设备端代码整体移入)
  control/  管理端(清理后)
  docs/     文档(PRD 移入 design/)
  README.md 根导航(新增)

清理:
- control/.brainstorm 临时草稿删除
- control 根级重复文档(API表/PRD_04)并入 docs/design/
- control/plan.md -> docs/implementation/control-plan.md
- control/safesightd-linux-arm64 二进制取消版本控制(.gitignore)
- edge/transform 模型转换产物归入 models/,onnx/pt 大源文件取消跟踪(.gitignore)
- Readme.md(PRD) -> docs/design/PRD_Product_v1.2.md(避开 README 大小写冲突)

更新:
- 根 README.md 导航、docs/README.md 文档索引
- deployment.md/检查表路径加 edge/ 前缀
- .gitignore 重写(edge/control 分区规则)
2026-08-02 11:39:54 +08:00

59 lines
1.7 KiB
C++
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#pragma once
#include "frame/frame.h"
#include <vector>
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