tea_detect.h 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  1. #pragma once
  2. #include <opencv.hpp>
  3. #include "logger.h"
  4. #include "data_def.h"
  5. #include "inference.h"
  6. namespace graft_cv {
  7. class RetinaDrop {
  8. struct DropBox {
  9. float x1;
  10. float y1;
  11. float x2;
  12. float y2;
  13. };
  14. struct DropRes {
  15. float confidence;
  16. DropBox drop_box;
  17. std::vector<cv::Point2f> keypoints;
  18. };
  19. public:
  20. explicit RetinaDrop(CGcvLogger* pLogger=0, float obj_th=0.6, float nms_th=0.4);
  21. ~RetinaDrop();
  22. bool LoadModel(std::string onnx_path);
  23. std::vector<Bbox> RunModel(cv::Mat& img, CGcvLogger* pInstanceLogger=0);
  24. bool IsModelLoaded();
  25. float GetNmsThreshold();
  26. void SetThreshold(float object_threshold, float nms_threshold);
  27. private:
  28. void generate_anchors();
  29. int post_process(
  30. cv::Mat &vec_Mat,
  31. std::vector<cv::Mat> &result_matrix,
  32. std::vector<RetinaDrop::DropRes>& valid_result);
  33. void nms_detect(
  34. std::vector<DropRes>& detections,
  35. std::vector<int>& keep);
  36. static float iou_calculate(
  37. const DropBox& det_a,
  38. const DropBox& det_b);
  39. int BATCH_SIZE; //default 1
  40. int INPUT_CHANNEL; //default 3
  41. int IMAGE_WIDTH; //default 640
  42. int IMAGE_HEIGHT; //default 640
  43. float m_obj_threshold; // default 0.5
  44. float m_nms_threshold; // default 0.45
  45. cv::Mat m_refer_matrix;
  46. int m_anchor_num;
  47. int m_bbox_head;
  48. std::vector<int> m_feature_sizes;
  49. std::vector<int> m_feature_steps;
  50. std::vector<int> m_feature_maps;
  51. std::vector<std::vector<int>>m_anchor_sizes;
  52. int m_sum_of_feature;
  53. cv::dnn::Net m_model;
  54. float m_variance[2];
  55. cv::Scalar m_img_mean;
  56. cv::Size m_size_detection;
  57. bool m_model_loaded;
  58. CGcvLogger* m_pLogger;
  59. };
  60. class YoloDrop {
  61. struct DropBox {
  62. float x1;
  63. float y1;
  64. float x2;
  65. float y2;
  66. };
  67. struct DropRes {
  68. float confidence;
  69. DropBox drop_box;
  70. std::vector<cv::Point2f> keypoints;
  71. };
  72. public:
  73. explicit YoloDrop(CGcvLogger* pLogger = 0, float obj_th = 0.6, float nms_th = 0.4);
  74. ~YoloDrop();
  75. bool LoadModel(std::string onnx_path);
  76. std::vector<Bbox> RunModel(cv::Mat& img, CGcvLogger* pInstanceLogger = 0);
  77. bool IsModelLoaded();
  78. float GetNmsThreshold();
  79. void SetThreshold(float object_threshold, float nms_threshold);
  80. private:
  81. Inference m_infer;
  82. void generate_anchors();
  83. int post_process(
  84. cv::Mat &vec_Mat,
  85. std::vector<cv::Mat> &result_matrix,
  86. std::vector<YoloDrop::DropRes>& valid_result);
  87. void nms_detect(
  88. std::vector<DropRes>& detections,
  89. std::vector<int>& keep);
  90. static float iou_calculate(
  91. const DropBox& det_a,
  92. const DropBox& det_b);
  93. int BATCH_SIZE; //default 1
  94. int INPUT_CHANNEL; //default 3
  95. int IMAGE_WIDTH; //default 640
  96. int IMAGE_HEIGHT; //default 640
  97. float m_obj_threshold; // default 0.5
  98. float m_nms_threshold; // default 0.45
  99. cv::Mat m_refer_matrix;
  100. int m_anchor_num;
  101. int m_bbox_head;
  102. std::vector<int> m_feature_sizes;
  103. std::vector<int> m_feature_steps;
  104. std::vector<int> m_feature_maps;
  105. std::vector<std::vector<int>>m_anchor_sizes;
  106. int m_sum_of_feature;
  107. cv::dnn::Net m_model;
  108. float m_variance[2];
  109. cv::Scalar m_img_mean;
  110. cv::Size m_size_detection;
  111. bool m_model_loaded;
  112. CGcvLogger* m_pLogger;
  113. };
  114. }