#ifndef __ABANDOBJ_CFG_H #define __ABANDOBJ_CFG_H #include "MAS_AlgoDef.h" #define NAMESPACE_ABANDOBJ_BEGIN namespace abandobj { #define NAMESPACE_ABANDOBJ_END }; NAMESPACE_MAS_BEGIN NAMESPACE_ABANDOBJ_BEGIN struct AbandObjBuild { std::string algo; TZ_INT factor; TZ_DOUBLE short_term_rate; TZ_INT short_term_history; TZ_DOUBLE long_term_rate; TZ_INT long_term_history; TZ_DOUBLE var_threshold; TZ_BOOL detect_shadows; TZ_DOUBLE iou_threshold; TZ_DOUBLE area_threshold; TZ_DOUBLE perimeter_threshold; std::string toJson() const { tzc::json::JsonDoc document; document.SetObject(); tzc::json::setFiled(document, "algo", algo); tzc::json::setFiled(document, "factor", factor); tzc::json::setFiled(document, "short_term_rate", short_term_rate); tzc::json::setFiled(document, "short_term_history", short_term_history); tzc::json::setFiled(document, "long_term_rate", long_term_rate); tzc::json::setFiled(document, "long_term_history", long_term_history); tzc::json::setFiled(document, "var_threshold", var_threshold); tzc::json::setFiled(document, "detect_shadows", detect_shadows); tzc::json::setFiled(document, "iou_threshold", iou_threshold); tzc::json::setFiled(document, "area_threshold", area_threshold); tzc::json::setFiled(document, "perimeter_threshold", perimeter_threshold); return tzc::json::ValueToJson(document); } static TZ_BOOL fromJson(const std::string& json, AbandObjBuild& value) { tzc::json::JsonDoc document; document.Parse(json.c_str()); if (document.HasParseError()) { return FALSE; } value.algo = tzc::json::getFiled(document, "algo", "MOG2"); value.factor = tzc::json::getFiled(document, "factor", 4); value.short_term_rate = tzc::json::getFiled(document, "short_term_rate", 0.01); value.short_term_history = tzc::json::getFiled(document, "short_term_history", 200); value.long_term_rate = tzc::json::getFiled(document, "long_term_rate", 0.0005); value.long_term_history = tzc::json::getFiled(document, "long_term_history", 5000); value.var_threshold = tzc::json::getFiled(document, "var_threshold", 16.0); value.detect_shadows = tzc::json::getFiled(document, "detect_shadows", FALSE); value.iou_threshold = tzc::json::getFiled(document, "iou_threshold", 0.6); value.area_threshold = tzc::json::getFiled(document, "area_threshold", 625.0); value.perimeter_threshold = tzc::json::getFiled(document, "perimeter_threshold", 100.0); return TRUE; } }; struct AbandObjCfg{ TZ_INT freq; std::vector focusArea; std::vector ignoreArea; std::string algo; TZ_INT factor; TZ_DOUBLE short_term_rate; TZ_INT short_term_history; TZ_DOUBLE long_term_rate; TZ_INT long_term_history; TZ_DOUBLE var_threshold; TZ_BOOL detect_shadows; TZ_DOUBLE iou_threshold; TZ_DOUBLE area_threshold; TZ_DOUBLE perimeter_threshold; std::string toJson() const { tzc::json::JsonDoc document; document.SetObject(); tzc::json::setFiled(document, "freq", freq); tzc::json::setFiledArrayObject(document, "focusArea", focusArea); tzc::json::setFiledArrayObject(document, "ignoreArea", ignoreArea); tzc::json::setFiled(document, "algo", algo); tzc::json::setFiled(document, "factor", factor); tzc::json::setFiled(document, "short_term_rate", short_term_rate); tzc::json::setFiled(document, "short_term_history", short_term_history); tzc::json::setFiled(document, "long_term_rate", long_term_rate); tzc::json::setFiled(document, "long_term_history", long_term_history); tzc::json::setFiled(document, "var_threshold", var_threshold); tzc::json::setFiled(document, "detect_shadows", detect_shadows); tzc::json::setFiled(document, "iou_threshold", iou_threshold); tzc::json::setFiled(document, "area_threshold", area_threshold); tzc::json::setFiled(document, "perimeter_threshold", perimeter_threshold); return tzc::json::ValueToJson(document); } static TZ_BOOL fromJson(const std::string& json, AbandObjCfg& value) { tzc::json::JsonDoc document; document.Parse(json.c_str()); if (document.HasParseError()) { return FALSE; } value.freq = tzc::json::getFiled(document, "freq", 0); value.algo = tzc::json::getFiled(document, "algo", "MOG"); value.factor = tzc::json::getFiled(document, "factor", 4); value.short_term_rate = tzc::json::getFiled(document, "short_term_rate", 0.01); value.short_term_history = tzc::json::getFiled(document, "short_term_history", 200); value.long_term_rate = tzc::json::getFiled(document, "long_term_rate", 0.0005); value.long_term_history = tzc::json::getFiled(document, "long_term_history", 5000); value.var_threshold = tzc::json::getFiled(document, "var_threshold", 16.0); value.detect_shadows = tzc::json::getFiled(document, "detect_shadows", FALSE); value.iou_threshold = tzc::json::getFiled(document, "iou_threshold", 0.6); value.area_threshold = tzc::json::getFiled(document, "area_threshold", 625.0); value.perimeter_threshold = tzc::json::getFiled(document, "perimeter_threshold", 100.0); TZ_BOOL rst = TRUE; rst &= tzc::json::ConverArrayObject(document, "focusArea", value.focusArea); rst &= tzc::json::ConverArrayObject(document, "ignoreArea", value.ignoreArea); return rst; } }; enum ProposalStatus { Overlap = 0, Active = 1, Accepted = 2 }; struct Proposal { TZ_DOUBLE x; TZ_DOUBLE y; TZ_DOUBLE w; TZ_DOUBLE h; TZ_INT life; ProposalStatus status; Proposal() : x(0.0), y(0.0), w(0.0), h(0.0), life(10), status(Active) {} Proposal(const Proposal& proposal) : x(proposal.x), y(proposal.y), w(proposal.w), h(proposal.h), life(proposal.life), status(proposal.status) {} std::string toJson() const { tzc::json::JsonDoc document; document.SetObject(); tzc::json::setFiled(document, "x", x); tzc::json::setFiled(document, "y", y); tzc::json::setFiled(document, "w", w); tzc::json::setFiled(document, "h", h); tzc::json::setFiled(document, "life", life); tzc::json::setFiled(document, "status", static_cast(status)); return tzc::json::ValueToJson(document); } static TZ_BOOL fromJson(const std::string& json, Proposal& value) { tzc::json::JsonDoc document; document.Parse(json.c_str()); if (document.HasParseError()) { return FALSE; } value.x = tzc::json::getFiled(document, "x", 0.0); value.y = tzc::json::getFiled(document, "y", 0.0); value.w = tzc::json::getFiled(document, "w", 0.0); value.h = tzc::json::getFiled(document, "h", 0.0); value.life = tzc::json::getFiled(document, "life", 10); value.status = static_cast(tzc::json::getFiled(document, "status", 1)); return TRUE; } }; struct AbandObjDetectResult{ std::vector proposals; std::string toJson() const { tzc::json::JsonDoc document; document.SetObject(); tzc::json::setFiledArrayObject(document, "proposals", proposals); return tzc::json::ValueToJson(document); } static TZ_BOOL fromJson(const std::string& json, AbandObjDetectResult& value) { tzc::json::JsonDoc document; document.Parse(json.c_str()); if(document.HasParseError()) { return FALSE; } TZ_BOOL rst = TRUE; rst &= tzc::json::ConverArrayObject(document, "proposals", value.proposals); return rst; } }; NAMESPACE_ABANDOBJ_END NAMESPACE_MAS_END #endif