Newer
Older
lynxi-plugin / src / osd / inc / carPlatePostProcess / detect.h
/**
 *@file detect.h
 *@author lynxi
 *@version v1.0
 *@date 2023-02-20
 *@par Copyright:
 *© 2022 北京灵汐科技有限公司 版权所有。
 * 注意:以下内容均为北京灵汐科技有限公司原创,未经本公司允许,不得转载,否则将视为侵权;对于不遵守此声明或者其他违法使用以下内容者,本公司依法保留追究权。\n
 *© 2022 Lynxi Technologies Co., Ltd. All rights reserved.
 * NOTICE: All information contained here is, and remains the property of Lynxi.
 *This file can not be copied or distributed without the permission of Lynxi
 *Technologies Co., Ltd.
 *@brief 检测模型推理结果定义
 */

#ifndef __DETECT_H_
#define __DETECT_H_

#include <string>
#include <vector>
#include <queue>
#include <lyn_codec_com.h>
#include <memory>
#include "drawTool.h"
#include "post_process.h"
const static std::wstring PLATE_DATA =
    L"京沪津渝冀晋蒙辽吉黑苏浙皖闽赣鲁豫鄂湘粤桂琼川贵云藏陕甘青宁新0123456789A"
    L"BCDEFGHJKLMNPQRSTUVWXYZ港学使警澳挂军北南广沈兰成济海民航空";

template <typename T>
class BlockQueue;
  // 推理结果
typedef struct {
  // 坐标 左
  float xmin;
  // 坐标 上
  float ymin;
  // 坐标 右
  float xmax;
  // 坐标 下
  float ymax;
  // 最高置信度
  float score;
  // 分类id
  int id;
  // 分类名
  const char *class_name;
} BboxResult;

// 推理结果集
typedef struct {
  // 推理结果数
  int boxNum;
  // 推理结果序列
  BboxResult *result;
} DetectionResult;
// 目标检测类型
typedef enum {
  // 全目标检测
  TARGET_DETECT_TYPE_ALL = 1,
  // 行人检测
  TARGET_DETECT_TYPE_PERSON,
  // 口罩检测
  TARGET_DETECT_TYPE_FACEMASK,
  // 烟火检测
  TARGET_DETECT_TYPE_FIRESMOKE
} TargetDetectType;


typedef struct{
    lynBoxesInfo* hostBoxInfo;    // host侧的boxInfo信息,从deviceBoxInfo复制而来
    lynBoxesInfo* deviceBoxInfo;  // device侧的boxInfo信息
    lynFrame_t* frame;
} DetectionFrame;


// yolo后处理信息
typedef struct {
  // 模型输入图像高
  int height;
  // 模型输入图像宽
  int width;
  // 原始图像高
  int ori_height;
  // 原始图像宽
  int ori_width;
  // 置信度阈值
  float score_threshold;
  // nms阈值
  float nms_threshold;
  // 默认500
  int nms_top_k;
  // 默认1
  int is_pad_resize;
  // 模型推理数据
  void *output_tensor;
  // 后处理结果
  lynBoxesInfo * post_process_result;
} YoloPostProcessInfo_t;



// 模型配置信息
struct Yolov5sConfig {
  std::vector<int> strides;
  std::vector<std::vector<std::pair<double, double>>> anchors_table;
  int class_num;
  std::vector<std::string> class_names;
};

// yolov5s模型配置
const Yolov5sConfig default_yolov5s_config = {
    {8, 16, 32},
    {{{10, 13}, {16, 30}, {33, 23}},
     {{30, 61}, {62, 45}, {59, 119}},
     {{116, 90}, {156, 198}, {373, 326}}},
    80,
    {"person",        "bicycle",      "car",
     "motorcycle",    "airplane",     "bus",
     "train",         "truck",        "boat",
     "traffic light", "fire hydrant", "stop sign",
     "parking meter", "bench",        "bird",
     "cat",           "dog",          "horse",
     "sheep",         "cow",          "elephant",
     "bear",          "zebra",        "giraffe",
     "backpack",      "umbrella",     "handbag",
     "tie",           "suitcase",     "frisbee",
     "skis",          "snowboard",    "sports ball",
     "kite",          "baseball bat", "baseball glove",
     "skateboard",    "surfboard",    "tennis racket",
     "bottle",        "wine glass",   "cup",
     "fork",          "knife",        "spoon",
     "bowl",          "banana",       "apple",
     "sandwich",      "orange",       "broccoli",
     "carrot",        "hot dog",      "pizza",
     "donut",         "cake",         "chair",
     "couch",         "potted plant", "bed",
     "dining table",  "toilet",       "tv",
     "laptop",        "mouse",        "remote",
     "keyboard",      "cell phone",   "microwave",
     "oven",          "toaster",      "sink",
     "refrigerator",  "book",         "clock",
     "vase",          "scissors",     "teddy bear",
     "hair drier",    "toothbrush"}};

// 口罩检测模型配置
const Yolov5sConfig facemask_config = {{8, 16, 32},
                                       {{{10, 13}, {16, 30}, {33, 23}},
                                        {{30, 61}, {62, 45}, {59, 119}},
                                        {{116, 90}, {156, 198}, {373, 326}}},
                                       2,
                                       {"face", "face_mask"}};

// 烟火检测模型配置
const Yolov5sConfig firesmoke_config = {{8, 16, 32},
                                        {{{10, 13}, {16, 30}, {33, 23}},
                                         {{30, 61}, {62, 45}, {59, 119}},
                                         {{116, 90}, {156, 198}, {373, 326}}},
                                        2,
                                        {"fire", "smoke"}};

// 车牌检测模型配置
const Yolov5sConfig carplate_config = {{8, 16, 32},
                                       {{{10, 13}, {16, 30}, {33, 23}},
                                        {{30, 61}, {62, 45}, {59, 119}},
                                        {{116, 90}, {156, 198}, {373, 326}}},
                                       1,
                                       {"carplate"}};


// 目标信息
typedef struct {
  // 坐标信息
  int left;
  int top;
  int width;
  int height;
  float confidence = 0.0f;
  // 文本信息
  char info[32];
} TARGET_INFO;

typedef struct {
  // 文本信息
  lynFrame_t* frame;
  // 检测目标信息数组
  std::shared_ptr<TARGET_INFO> targets;
  // 检测目标信息数组数量
  int targetNum;
} IMAGE_DETECT;


typedef struct{
    DetectionResult detection_result;
    lynFrame_t* frame;
} DetectFrame;

typedef struct {
    // std::shared_ptr<std::vector<std::shared_ptr<TARGET_INFO>>> recog_result;
    std::shared_ptr<std::vector<TARGET_INFO>> recog_result;
    lynFrame_t* frame;
} RecognitionFrame;

struct lynTargetInfo {
  uint32_t boxesNum;          // target数量
  TARGET_INFO targets[10];  // target信息
};

#endif