DetectionPostProcess
======================

DetectionPostProcess 算子用于目标检测模型的后处理阶段，对网络预测的候选框和置信度进行解码、筛选和非极大值抑制（NMS），输出最终检测结果。  
其主要功能包括：
1. 根据 anchor 信息对候选框进行解码；
2. 对各类别的候选框执行 NMS 操作；
3. 输出选中的检测框、类别及分数。

输入：
    - **input_boxes** - 检测框坐标数据地址，形状为 ``[num_boxes, 4]``。
    - **input_scores** - 每个检测框对应的置信度分数，形状为 ``[num_boxes, num_classes_with_bg_]``。
    - **anchors** - Anchor 坐标数据地址，形状为 ``[num_boxes, 4]``。
    - **num_boxes** - 候选框数量。
    - **num_classes_with_bg** - 含背景类在内的类别数量。
    - **core_mask (int, 可选)** - 核掩码（仅适用于共享存储版本）。
    - **param** - 算子参数结构体，包含 NMS 阈值、检测数量限制、坐标缩放因子等。

    **结构体定义：**

    .. code-block:: c
        :linenos:

        typedef struct {
            bool use_regular_nms;
            int num_classes;
            int max_detections;
            int max_classes_per_detection;  // Fast NMS使用
            int detections_per_class;       // Regular NMS使用
            float nms_score_threshold;
            float nms_iou_threshold;
            float y_scale;
            float x_scale;
            float h_scale;
            float w_scale;
            int num_boxes;
            int num_classes_with_bg;

            void *decoded_boxes;
            uint8_t *nms_candidate;
            int32_t *selected;
            float *scores;
            int32_t *indexes;
            float *all_class_scores;
            int32_t *all_class_indexes;
            int32_t *single_class_indexes;

            // INT8 量化参数（仅在 Int8 模式下使用）
            float boxes_scale;
            int32_t boxes_zero_point;
            float scores_scale;
            int32_t scores_zero_point;

        } DetectionPostProcessParameter;
输出：
    - **output_boxes** - 输出检测框坐标。
    - **output_classes** - 输出检测框类别索引。
    - **output_scores** - 输出检测框对应的置信度。
    - **output_num** - 实际输出的检测框数量。

支持平台：
    ``FT78NE``  
    ``MT7004``  

.. note::
    - FT78NE 支持 fp32, int8  
    - MT7004 支持 fp16, fp32   

**共享存储版本:**

.. c:function:: void fp_detection_post_process_s(const float *input_boxes, const float *input_scores, const float *anchors, float *output_boxes, float *output_classes, float *output_scores, float *output_num, DetectionPostProcessParameter *param, int core_mask)
.. c:function:: void i8_detection_post_process_s(const int8_t *input_boxes, const int8_t *input_scores, const float *anchors, float *output_boxes, float *output_classes, float *output_scores, float *output_num, DetectionPostProcessParameter *param, int core_mask)
.. c:function:: void hp_detection_post_process_s(const half *input_boxes, const half *input_scores, const half *anchors, half *output_boxes, float *output_classes, half *output_scores, float *output_num, DetectionPostProcessParameter *param, int core_mask)

    **C调用示例：**

    .. code-block:: c
        :linenos:
        :emphasize-lines: 30

        //FT78NE示例
        #include <stdio.h>

        int main(int argc, char* argv[]) {
            float *input_boxes = (float *)0xA0000000;
            float *input_scores = (float *)0xA1000000;
            float *anchors = (float *)0xA2000000;
            float *output_boxes = (float *)0xA3000000;
            float *output_classes = (float *)0xA4000000;
            float *output_scores = (float *)0xA5000000;
            float *output_num = (float *)0xA6000000;
            DetectionPostProcessParameter* param = (DetectionPostProcessParameter*)0xA7000000;

            param->use_regular_nms = true;
            param->num_classes = 3;
            param->max_detections = 50;
            param->max_classes_per_detection = 1;
            param->detections_per_class = 50;
            param->nms_score_threshold = 0.1f;
            param->nms_iou_threshold = 0.5f;
            param->y_scale = 10.0f;
            param->x_scale = 10.0f;
            param->h_scale = 5.0f;
            param->w_scale = 5.0f;
            param->num_boxes = 100;
            param->num_classes_with_bg = 4;

            int core_mask = 0xff;

            fp_detection_post_process_s(input_boxes, input_scores, anchors, output_boxes, output_classes, output_scores, output_num, param, core_mask);
            return 0;
        }

**私有存储版本:**

.. c:function:: void fp_detection_post_process_p(const float *input_boxes, const float *input_scores, const float *anchors, float *output_boxes, float *output_classes, float *output_scores, float *output_num, DetectionPostProcessParameter *param)
.. c:function:: void i8_detection_post_process_p(const int8_t *input_boxes, const int8_t *input_scores, const float *anchors, float *output_boxes, float *output_classes, float *output_scores, float *output_num, DetectionPostProcessParameter *param)
.. c:function:: void hp_detection_post_process_p(const half *input_boxes, const half *input_scores, const half *anchors, half *output_boxes, float *output_classes, half *output_scores, float *output_num, DetectionPostProcessParameter *param)

    **C调用示例：**

    .. code-block:: c
        :linenos:
        :emphasize-lines: 29

        //MT7004示例
        #include <stdio.h>

        int main(int argc, char* argv[]) {
            DetectionPostProcessParameter param;

            param.use_regular_nms = 1;
            param.num_classes = 3;
            param.max_detections = 50;
            param.max_classes_per_detection = 1;
            param.detections_per_class = 50;
            param.nms_score_threshold = 0.1f;
            param.nms_iou_threshold = 0.5f;
            param.y_scale = 10.0f;
            param.x_scale = 10.0f;
            param.h_scale = 5.0f;
            param.w_scale = 5.0f;
            param.num_boxes = 1917;
            param.num_classes_with_bg = 4;

            float *input_boxes = (float *)0xA0000000;
            float *input_scores = (float *)0xA1000000;
            float *anchors = (float *)0xA2000000;
            float *output_boxes = (float *)0xA3000000;
            float *output_classes = (float *)0xA4000000;
            float *output_scores = (float *)0xA5000000;
            float *output_num = (float *)0xA6000000;

            fp_detection_post_process_p(input_boxes, input_scores, anchors, output_boxes, output_classes, output_scores, output_num, param);
            return 0;
        }
