YoloCrowdCfg.h 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209
  1. #ifndef __YOLOCROWD_CFG_H
  2. #define __YOLOCROWD_CFG_H
  3. #include "MAS_AlgoDef.h"
  4. #define NAMESPACE_YOLOCROWD_BEGIN namespace yolocrowd {
  5. #define NAMESPACE_YOLOCROWD_END };
  6. NAMESPACE_MAS_BEGIN
  7. NAMESPACE_YOLOCROWD_BEGIN
  8. struct YoloCrowdBuild {
  9. TZ_INT gpu_id;
  10. TZ_INT max_objects;
  11. TZ_DOUBLE confidence_threshold;
  12. TZ_DOUBLE nms_threshold;
  13. std::string model_path;
  14. std::string toJson() const
  15. {
  16. tzc::json::JsonDoc document;
  17. document.SetObject();
  18. tzc::json::setFiled(document, "gpu_id", gpu_id);
  19. tzc::json::setFiled(document, "max_objects", max_objects);
  20. tzc::json::setFiled(document, "confidence_threshold", confidence_threshold);
  21. tzc::json::setFiled(document, "nms_threshold", nms_threshold);
  22. tzc::json::setFiled(document, "model_path", model_path);
  23. return tzc::json::ValueToJson(document);
  24. }
  25. static TZ_BOOL fromJson(const std::string& json, YoloCrowdBuild& value)
  26. {
  27. tzc::json::JsonDoc document;
  28. document.Parse(json.c_str());
  29. if (document.HasParseError())
  30. {
  31. return FALSE;
  32. }
  33. value.gpu_id = tzc::json::getFiled(document, "gpu_id", 0);
  34. value.max_objects = tzc::json::getFiled(document, "max_objects", 1024);
  35. value.confidence_threshold = tzc::json::getFiled(document, "confidence_threshold", 0.10);
  36. value.nms_threshold = tzc::json::getFiled(document, "nms_threshold", 0.45);
  37. value.model_path = tzc::json::getFiled(document, "model_path", "");
  38. return TRUE;
  39. }
  40. };
  41. struct TargetInfo {
  42. TZ_INT target_class;
  43. TZ_DOUBLE target_threshold;
  44. std::string toJson() const
  45. {
  46. tzc::json::JsonDoc document;
  47. document.SetObject();
  48. tzc::json::setFiled(document, "target_class", target_class);
  49. tzc::json::setFiled(document, "target_threshold", target_threshold);
  50. return tzc::json::ValueToJson(document);
  51. }
  52. static TZ_BOOL fromJson(const std::string& json, TargetInfo& value)
  53. {
  54. tzc::json::JsonDoc document;
  55. document.Parse(json.c_str());
  56. if (document.HasParseError())
  57. {
  58. return FALSE;
  59. }
  60. value.target_class = tzc::json::getFiled(document, "target_class", 0);
  61. value.target_threshold = tzc::json::getFiled(document, "target_threshold", 0.7);
  62. return TRUE;
  63. }
  64. };
  65. struct YoloCrowdCfg{
  66. TZ_INT freq;
  67. TargetInfo target;
  68. std::vector<AreaBox> focusArea;
  69. std::vector<AreaBox> ignoreArea;
  70. std::string toJson() const
  71. {
  72. tzc::json::JsonDoc document;
  73. document.SetObject();
  74. tzc::json::setFiled(document, "freq", freq);
  75. tzc::json::setFiledObject(document, "target", target);
  76. tzc::json::setFiledArrayObject(document, "focusArea", focusArea);
  77. tzc::json::setFiledArrayObject(document, "ignoreArea", ignoreArea);
  78. return tzc::json::ValueToJson(document);
  79. }
  80. static TZ_BOOL fromJson(const std::string& json, YoloCrowdCfg& value)
  81. {
  82. tzc::json::JsonDoc document;
  83. document.Parse(json.c_str());
  84. if (document.HasParseError())
  85. {
  86. return FALSE;
  87. }
  88. value.freq = tzc::json::getFiled(document, "freq", 0);
  89. TZ_BOOL rst = TRUE;
  90. rst &= tzc::json::ConverObject(document, "target", value.target);
  91. rst &= tzc::json::ConverArrayObject(document, "focusArea", value.focusArea);
  92. rst &= tzc::json::ConverArrayObject(document, "ignoreArea", value.ignoreArea);
  93. return rst;
  94. }
  95. };
  96. struct DetObj
  97. {
  98. TZ_INT obj_class;
  99. TZ_DOUBLE left;
  100. TZ_DOUBLE top;
  101. TZ_DOUBLE right;
  102. TZ_DOUBLE bottom;
  103. TZ_DOUBLE confidence;
  104. DetObj() : obj_class(0), left(0.0), top(0.0), right(0.0), bottom(0.0), confidence(0.0) {}
  105. DetObj(const DetObj& obj)
  106. : obj_class(obj.obj_class), left(obj.left), top(obj.top), right(obj.right),
  107. bottom(obj.bottom), confidence(obj.confidence) {}
  108. std::string toJson() const
  109. {
  110. tzc::json::JsonDoc document;
  111. document.SetObject();
  112. tzc::json::setFiled(document, "obj_class", obj_class);
  113. tzc::json::setFiled(document, "left", left);
  114. tzc::json::setFiled(document, "top", top);
  115. tzc::json::setFiled(document, "right", right);
  116. tzc::json::setFiled(document, "bottom", bottom);
  117. tzc::json::setFiled(document, "confidence", confidence);
  118. return tzc::json::ValueToJson(document);
  119. }
  120. static TZ_BOOL fromJson(const std::string& json, DetObj& value)
  121. {
  122. tzc::json::JsonDoc document;
  123. document.Parse(json.c_str());
  124. if (document.HasParseError())
  125. {
  126. return FALSE;
  127. }
  128. value.obj_class = tzc::json::getFiled(document, "obj_class", 0);
  129. value.left = tzc::json::getFiled(document, "left", 0.0f);
  130. value.top = tzc::json::getFiled(document, "top", 0.0f);
  131. value.right = tzc::json::getFiled(document, "right", 0.0f);
  132. value.bottom = tzc::json::getFiled(document, "bottom", 0.0f);
  133. value.confidence = tzc::json::getFiled(document, "confidence", 0.0f);
  134. return TRUE;
  135. }
  136. };
  137. struct YoloCrowdDetectResult{
  138. std::vector<DetObj> objs;
  139. std::string toJson() const
  140. {
  141. tzc::json::JsonDoc document;
  142. document.SetObject();
  143. tzc::json::setFiledArrayObject(document, "objs", objs);
  144. return tzc::json::ValueToJson(document);
  145. }
  146. static TZ_BOOL fromJson(const std::string& json, YoloCrowdDetectResult& value)
  147. {
  148. tzc::json::JsonDoc document;
  149. document.Parse(json.c_str());
  150. if(document.HasParseError())
  151. {
  152. return FALSE;
  153. }
  154. TZ_BOOL rst = TRUE;
  155. rst &= tzc::json::ConverArrayObject(document, "objs", value.objs);
  156. return rst;
  157. }
  158. };
  159. NAMESPACE_YOLOCROWD_END
  160. NAMESPACE_MAS_END
  161. #endif