AbandObjCfg.h 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230
  1. #ifndef __ABANDOBJ_CFG_H
  2. #define __ABANDOBJ_CFG_H
  3. #include "MAS_AlgoDef.h"
  4. #define NAMESPACE_ABANDOBJ_BEGIN namespace abandobj {
  5. #define NAMESPACE_ABANDOBJ_END };
  6. NAMESPACE_MAS_BEGIN
  7. NAMESPACE_ABANDOBJ_BEGIN
  8. struct AbandObjBuild {
  9. std::string algo;
  10. TZ_INT factor;
  11. TZ_DOUBLE short_term_rate;
  12. TZ_INT short_term_history;
  13. TZ_DOUBLE long_term_rate;
  14. TZ_INT long_term_history;
  15. TZ_DOUBLE var_threshold;
  16. TZ_BOOL detect_shadows;
  17. TZ_DOUBLE iou_threshold;
  18. TZ_DOUBLE area_threshold;
  19. TZ_DOUBLE perimeter_threshold;
  20. std::string toJson() const
  21. {
  22. tzc::json::JsonDoc document;
  23. document.SetObject();
  24. tzc::json::setFiled(document, "algo", algo);
  25. tzc::json::setFiled(document, "factor", factor);
  26. tzc::json::setFiled(document, "short_term_rate", short_term_rate);
  27. tzc::json::setFiled(document, "short_term_history", short_term_history);
  28. tzc::json::setFiled(document, "long_term_rate", long_term_rate);
  29. tzc::json::setFiled(document, "long_term_history", long_term_history);
  30. tzc::json::setFiled(document, "var_threshold", var_threshold);
  31. tzc::json::setFiled(document, "detect_shadows", detect_shadows);
  32. tzc::json::setFiled(document, "iou_threshold", iou_threshold);
  33. tzc::json::setFiled(document, "area_threshold", area_threshold);
  34. tzc::json::setFiled(document, "perimeter_threshold", perimeter_threshold);
  35. return tzc::json::ValueToJson(document);
  36. }
  37. static TZ_BOOL fromJson(const std::string& json, AbandObjBuild& value)
  38. {
  39. tzc::json::JsonDoc document;
  40. document.Parse(json.c_str());
  41. if (document.HasParseError())
  42. {
  43. return FALSE;
  44. }
  45. value.algo = tzc::json::getFiled(document, "algo", "MOG2");
  46. value.factor = tzc::json::getFiled(document, "factor", 4);
  47. value.short_term_rate = tzc::json::getFiled(document, "short_term_rate", 0.01);
  48. value.short_term_history = tzc::json::getFiled(document, "short_term_history", 200);
  49. value.long_term_rate = tzc::json::getFiled(document, "long_term_rate", 0.0005);
  50. value.long_term_history = tzc::json::getFiled(document, "long_term_history", 5000);
  51. value.var_threshold = tzc::json::getFiled(document, "var_threshold", 16.0);
  52. value.detect_shadows = tzc::json::getFiled(document, "detect_shadows", FALSE);
  53. value.iou_threshold = tzc::json::getFiled(document, "iou_threshold", 0.6);
  54. value.area_threshold = tzc::json::getFiled(document, "area_threshold", 625.0);
  55. value.perimeter_threshold = tzc::json::getFiled(document, "perimeter_threshold", 100.0);
  56. return TRUE;
  57. }
  58. };
  59. struct AbandObjCfg{
  60. TZ_INT freq;
  61. std::vector<AreaBox> focusArea;
  62. std::vector<AreaBox> ignoreArea;
  63. std::string algo;
  64. TZ_INT factor;
  65. TZ_DOUBLE short_term_rate;
  66. TZ_INT short_term_history;
  67. TZ_DOUBLE long_term_rate;
  68. TZ_INT long_term_history;
  69. TZ_DOUBLE var_threshold;
  70. TZ_BOOL detect_shadows;
  71. TZ_DOUBLE iou_threshold;
  72. TZ_DOUBLE area_threshold;
  73. TZ_DOUBLE perimeter_threshold;
  74. std::string toJson() const
  75. {
  76. tzc::json::JsonDoc document;
  77. document.SetObject();
  78. tzc::json::setFiled(document, "freq", freq);
  79. tzc::json::setFiledArrayObject(document, "focusArea", focusArea);
  80. tzc::json::setFiledArrayObject(document, "ignoreArea", ignoreArea);
  81. tzc::json::setFiled(document, "algo", algo);
  82. tzc::json::setFiled(document, "factor", factor);
  83. tzc::json::setFiled(document, "short_term_rate", short_term_rate);
  84. tzc::json::setFiled(document, "short_term_history", short_term_history);
  85. tzc::json::setFiled(document, "long_term_rate", long_term_rate);
  86. tzc::json::setFiled(document, "long_term_history", long_term_history);
  87. tzc::json::setFiled(document, "var_threshold", var_threshold);
  88. tzc::json::setFiled(document, "detect_shadows", detect_shadows);
  89. tzc::json::setFiled(document, "iou_threshold", iou_threshold);
  90. tzc::json::setFiled(document, "area_threshold", area_threshold);
  91. tzc::json::setFiled(document, "perimeter_threshold", perimeter_threshold);
  92. return tzc::json::ValueToJson(document);
  93. }
  94. static TZ_BOOL fromJson(const std::string& json, AbandObjCfg& value)
  95. {
  96. tzc::json::JsonDoc document;
  97. document.Parse(json.c_str());
  98. if (document.HasParseError())
  99. {
  100. return FALSE;
  101. }
  102. value.freq = tzc::json::getFiled(document, "freq", 0);
  103. value.algo = tzc::json::getFiled(document, "algo", "MOG");
  104. value.factor = tzc::json::getFiled(document, "factor", 4);
  105. value.short_term_rate = tzc::json::getFiled(document, "short_term_rate", 0.01);
  106. value.short_term_history = tzc::json::getFiled(document, "short_term_history", 200);
  107. value.long_term_rate = tzc::json::getFiled(document, "long_term_rate", 0.0005);
  108. value.long_term_history = tzc::json::getFiled(document, "long_term_history", 5000);
  109. value.var_threshold = tzc::json::getFiled(document, "var_threshold", 16.0);
  110. value.detect_shadows = tzc::json::getFiled(document, "detect_shadows", FALSE);
  111. value.iou_threshold = tzc::json::getFiled(document, "iou_threshold", 0.6);
  112. value.area_threshold = tzc::json::getFiled(document, "area_threshold", 625.0);
  113. value.perimeter_threshold = tzc::json::getFiled(document, "perimeter_threshold", 100.0);
  114. TZ_BOOL rst = TRUE;
  115. rst &= tzc::json::ConverArrayObject(document, "focusArea", value.focusArea);
  116. rst &= tzc::json::ConverArrayObject(document, "ignoreArea", value.ignoreArea);
  117. return rst;
  118. }
  119. };
  120. enum ProposalStatus {
  121. Overlap = 0,
  122. Active = 1,
  123. Accepted = 2
  124. };
  125. struct Proposal
  126. {
  127. TZ_DOUBLE x;
  128. TZ_DOUBLE y;
  129. TZ_DOUBLE w;
  130. TZ_DOUBLE h;
  131. TZ_INT life;
  132. ProposalStatus status;
  133. Proposal() : x(0.0), y(0.0), w(0.0), h(0.0), life(10), status(Active) {}
  134. Proposal(const Proposal& proposal)
  135. : x(proposal.x), y(proposal.y), w(proposal.w), h(proposal.h),
  136. life(proposal.life), status(proposal.status) {}
  137. std::string toJson() const
  138. {
  139. tzc::json::JsonDoc document;
  140. document.SetObject();
  141. tzc::json::setFiled(document, "x", x);
  142. tzc::json::setFiled(document, "y", y);
  143. tzc::json::setFiled(document, "w", w);
  144. tzc::json::setFiled(document, "h", h);
  145. tzc::json::setFiled(document, "life", life);
  146. tzc::json::setFiled(document, "status", static_cast<TZ_INT>(status));
  147. return tzc::json::ValueToJson(document);
  148. }
  149. static TZ_BOOL fromJson(const std::string& json, Proposal& value)
  150. {
  151. tzc::json::JsonDoc document;
  152. document.Parse(json.c_str());
  153. if (document.HasParseError())
  154. {
  155. return FALSE;
  156. }
  157. value.x = tzc::json::getFiled(document, "x", 0.0);
  158. value.y = tzc::json::getFiled(document, "y", 0.0);
  159. value.w = tzc::json::getFiled(document, "w", 0.0);
  160. value.h = tzc::json::getFiled(document, "h", 0.0);
  161. value.life = tzc::json::getFiled(document, "life", 10);
  162. value.status = static_cast<ProposalStatus>(tzc::json::getFiled(document, "status", 1));
  163. return TRUE;
  164. }
  165. };
  166. struct AbandObjDetectResult{
  167. std::vector<Proposal> proposals;
  168. std::string toJson() const
  169. {
  170. tzc::json::JsonDoc document;
  171. document.SetObject();
  172. tzc::json::setFiledArrayObject(document, "proposals", proposals);
  173. return tzc::json::ValueToJson(document);
  174. }
  175. static TZ_BOOL fromJson(const std::string& json, AbandObjDetectResult& value)
  176. {
  177. tzc::json::JsonDoc document;
  178. document.Parse(json.c_str());
  179. if(document.HasParseError())
  180. {
  181. return FALSE;
  182. }
  183. TZ_BOOL rst = TRUE;
  184. rst &= tzc::json::ConverArrayObject(document, "proposals", value.proposals);
  185. return rst;
  186. }
  187. };
  188. NAMESPACE_ABANDOBJ_END
  189. NAMESPACE_MAS_END
  190. #endif