yolov3_app.h 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  1. /******************************************************************************
  2. 版权所有 (C), 2019-2029, SDC OS 开源软件小组所有
  3. ******************************************************************************
  4. 文 件 名 : yolov3_app.h
  5. 版 本 号 : 初稿
  6. 作 者 : athina
  7. 生成日期 : 2020年7月4日
  8. 最近修改 :
  9. 功能描述 : yolov3业务流程
  10. 函数列表 :
  11. 修改历史 :
  12. 1.日 期 : 2020年7月4日
  13. 作 者 : athina
  14. 修改内容 : 创建文件
  15. ******************************************************************************/
  16. #ifndef __YOLOV3_APP_H__
  17. #define __YOLOV3_APP_H__
  18. #include <string>
  19. #include <memory>
  20. #include "yuv_queue.h"
  21. #include "sdc_data_src.h"
  22. #include "sdc_os_api.h"
  23. #include "tcpSerEpoll.h"
  24. #include "Ctimer.h"
  25. #include "inifile.h"
  26. #include "dataType/NettyClientCommandEnum.h"
  27. #include "dataType/NettyClientResultMsg.h"
  28. #include "dataType/NettyServerCommandEnum.h"
  29. #include "dataType/NettyServerResultMsg.h"
  30. #include "dataType/RecDeviceCommand.h"
  31. #include "dataType/RecDeviceInfo.h"
  32. #include "dataType/SendLogin.h"
  33. #include "dataType/SendHeartBeat.h"
  34. #include "dataType/SendDevice.h"
  35. #include "dataType/SendBird.h"
  36. namespace HWYolov3App
  37. {
  38. class ProtoBuffer;
  39. class IYuvDataSrc;
  40. class Yolov3App
  41. {
  42. public:
  43. virtual ~Yolov3App(void);
  44. int32_t Init(std::string &appName);
  45. int32_t SetYuvChanAttr(sdc_yuv_channel_param_s &yuv_param);
  46. int32_t LoadModel(unsigned int loadMode, std::string &modelName);
  47. virtual int32_t NNieParamInit(void);
  48. int32_t SubscribeYuvDataAndForward(std::shared_ptr<IYuvDataSrc> dataSrc);
  49. void SubscribeSerEpoll(std::shared_ptr<tcpSerEpoll> serEpoll);
  50. void SubscribeCTimer(std::shared_ptr<CTimer> heartbeatTimer, std::shared_ptr<CTimer> closeExpelTimer);
  51. void Destroy(void);
  52. uint32_t GetYuvChannelId(void) const;
  53. protected:
  54. Yolov3App(void);
  55. virtual void PreProcessYuvData(sdc_yuv_frame_s &frame, uint8_t *&yuv);
  56. virtual void PretreatObjectData(SDC_SSD_OBJECT_INFO_S &data) = 0;
  57. bool ConstructRectAreaData(const SDC_SSD_OBJECT_INFO_S &data, ProtoBuffer &buf);
  58. bool ConstructTargetData(const SDC_SSD_OBJECT_INFO_S &data, ProtoBuffer &buf);
  59. // 将uclass对应的数字,映射为具体目标,目标信息不能超过20字符
  60. virtual void ClassifyTargets(uint32_t uclass, uint8_t target[20]) = 0;
  61. // 打印目标检测信息
  62. virtual void PrintObjectInfo(const SDC_SSD_OBJECT_INFO_S &info) const;
  63. virtual void SendObjectsToWeb(const SDC_SSD_RESULT_S &stResult, sdc_yuv_frame_s &yuvFrame) = 0;
  64. virtual void SendOjbectsToMediaServer(const SDC_SSD_RESULT_S &stResult) = 0;
  65. static void SendHeartbeatData(void *arg);
  66. static void sendCloseExpelData(void *arg);
  67. SDC_SSD_INPUT_SIZE_S m_videoSize; // 输入模型的大小
  68. SDC_SSD_INPUT_SIZE_S m_inputSize; // 输入模型的大小
  69. // Yuv循环队列的默认大小为50
  70. static const int32_t MAX_YUV_BUF_NUM = 50;
  71. static float m_confidenceThres; // 置信度阈值
  72. // 定时器
  73. std::shared_ptr<tcpSerEpoll> m_serEpoll;
  74. std::shared_ptr<CTimer> m_heartbeatTimer;
  75. std::shared_ptr<CTimer> m_closeExpelTimer;
  76. int m_fdResultFifo = -1;
  77. std::string m_resultFifo = "/tmp/result";
  78. const std::string m_configSrc = "../config/config.ini";
  79. // 数据订阅
  80. int m_USER_DET_IMG_W = 960; // 指定订阅使用的检测分辨率宽
  81. int m_USER_DET_IMG_H = 544; // 指定订阅使用的检测分辨率高
  82. int m_USER_DET_FRAME_RATE = 25; // 指定订阅帧率
  83. int m_MODEL_INPUT_SIZE_WIDTH = 416; // 模型输入大小宽
  84. int m_MODEL_INPUT_SIZE_HEIGHT = 416; // 模型输入大小高
  85. private:
  86. Yolov3App(const Yolov3App&);
  87. Yolov3App& operator=(const Yolov3App&);
  88. Yolov3App(Yolov3App&&);
  89. Yolov3App& operator=(Yolov3App&&);
  90. // 构造元数据
  91. bool ConstructMetaData(const SDC_SSD_RESULT_S &stResult, ProtoBuffer &buf);
  92. // 处理线程函数
  93. static void* YuvDataProcThrd(void *arg); // YUV处理线程
  94. static void* VideoSrvReadThrd(void *arg); // 视频服务线程
  95. static void* WatchdogThread(void *arg); // 系统资源监控
  96. // 卸载NNiE WK模型
  97. int32_t UnLoadModel(void);
  98. // 展示检测目标信息
  99. void SendObjectsToSims(ProtoBuffer &buf, int32_t pts) const;
  100. std::string m_appName;
  101. std::string m_modelName;
  102. // ReceiveThread & ProcessThread
  103. pthread_t m_tidpProc;
  104. pthread_t m_tidpRecv;
  105. pthread_t m_tidpWatchdog;
  106. uint32_t m_yuvChnId;
  107. YuvQueue m_yuvQue; // 循环队列保存Yuv数据帧
  108. std::shared_ptr<IYuvDataSrc> m_dataSrc; // 指定数据源
  109. };
  110. }
  111. #endif /* __YOLOV3_APP_H__ */