123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209 |
- #ifndef __YOLOCROWD_CFG_H
- #define __YOLOCROWD_CFG_H
- #include "MAS_AlgoDef.h"
- #define NAMESPACE_YOLOCROWD_BEGIN namespace yolocrowd {
- #define NAMESPACE_YOLOCROWD_END };
- NAMESPACE_MAS_BEGIN
- NAMESPACE_YOLOCROWD_BEGIN
- struct YoloCrowdBuild {
- TZ_INT gpu_id;
- TZ_INT max_objects;
- TZ_DOUBLE confidence_threshold;
- TZ_DOUBLE nms_threshold;
- std::string model_path;
- std::string toJson() const
- {
- tzc::json::JsonDoc document;
- document.SetObject();
- tzc::json::setFiled(document, "gpu_id", gpu_id);
- tzc::json::setFiled(document, "max_objects", max_objects);
- tzc::json::setFiled(document, "confidence_threshold", confidence_threshold);
- tzc::json::setFiled(document, "nms_threshold", nms_threshold);
- tzc::json::setFiled(document, "model_path", model_path);
- return tzc::json::ValueToJson(document);
- }
- static TZ_BOOL fromJson(const std::string& json, YoloCrowdBuild& value)
- {
- tzc::json::JsonDoc document;
- document.Parse(json.c_str());
- if (document.HasParseError())
- {
- return FALSE;
- }
- value.gpu_id = tzc::json::getFiled(document, "gpu_id", 0);
- value.max_objects = tzc::json::getFiled(document, "max_objects", 1024);
- value.confidence_threshold = tzc::json::getFiled(document, "confidence_threshold", 0.10);
- value.nms_threshold = tzc::json::getFiled(document, "nms_threshold", 0.45);
- value.model_path = tzc::json::getFiled(document, "model_path", "");
- return TRUE;
- }
- };
- struct TargetInfo {
- TZ_INT target_class;
- TZ_DOUBLE target_threshold;
- std::string toJson() const
- {
- tzc::json::JsonDoc document;
- document.SetObject();
- tzc::json::setFiled(document, "target_class", target_class);
- tzc::json::setFiled(document, "target_threshold", target_threshold);
- return tzc::json::ValueToJson(document);
- }
- static TZ_BOOL fromJson(const std::string& json, TargetInfo& value)
- {
- tzc::json::JsonDoc document;
- document.Parse(json.c_str());
- if (document.HasParseError())
- {
- return FALSE;
- }
- value.target_class = tzc::json::getFiled(document, "target_class", 0);
- value.target_threshold = tzc::json::getFiled(document, "target_threshold", 0.7);
- return TRUE;
- }
- };
- struct YoloCrowdCfg{
- TZ_INT freq;
- TargetInfo target;
- std::vector<AreaBox> focusArea;
- std::vector<AreaBox> ignoreArea;
- std::string toJson() const
- {
- tzc::json::JsonDoc document;
- document.SetObject();
- tzc::json::setFiled(document, "freq", freq);
- tzc::json::setFiledObject(document, "target", target);
- tzc::json::setFiledArrayObject(document, "focusArea", focusArea);
- tzc::json::setFiledArrayObject(document, "ignoreArea", ignoreArea);
- return tzc::json::ValueToJson(document);
- }
- static TZ_BOOL fromJson(const std::string& json, YoloCrowdCfg& value)
- {
- tzc::json::JsonDoc document;
- document.Parse(json.c_str());
- if (document.HasParseError())
- {
- return FALSE;
- }
- value.freq = tzc::json::getFiled(document, "freq", 0);
- TZ_BOOL rst = TRUE;
- rst &= tzc::json::ConverObject(document, "target", value.target);
- rst &= tzc::json::ConverArrayObject(document, "focusArea", value.focusArea);
- rst &= tzc::json::ConverArrayObject(document, "ignoreArea", value.ignoreArea);
- return rst;
- }
- };
- struct DetObj
- {
- TZ_INT obj_class;
- TZ_DOUBLE left;
- TZ_DOUBLE top;
- TZ_DOUBLE right;
- TZ_DOUBLE bottom;
- TZ_DOUBLE confidence;
- DetObj() : obj_class(0), left(0.0), top(0.0), right(0.0), bottom(0.0), confidence(0.0) {}
- DetObj(const DetObj& obj)
- : obj_class(obj.obj_class), left(obj.left), top(obj.top), right(obj.right),
- bottom(obj.bottom), confidence(obj.confidence) {}
- std::string toJson() const
- {
- tzc::json::JsonDoc document;
- document.SetObject();
- tzc::json::setFiled(document, "obj_class", obj_class);
- tzc::json::setFiled(document, "left", left);
- tzc::json::setFiled(document, "top", top);
- tzc::json::setFiled(document, "right", right);
- tzc::json::setFiled(document, "bottom", bottom);
- tzc::json::setFiled(document, "confidence", confidence);
- return tzc::json::ValueToJson(document);
- }
- static TZ_BOOL fromJson(const std::string& json, DetObj& value)
- {
- tzc::json::JsonDoc document;
- document.Parse(json.c_str());
- if (document.HasParseError())
- {
- return FALSE;
- }
- value.obj_class = tzc::json::getFiled(document, "obj_class", 0);
- value.left = tzc::json::getFiled(document, "left", 0.0f);
- value.top = tzc::json::getFiled(document, "top", 0.0f);
- value.right = tzc::json::getFiled(document, "right", 0.0f);
- value.bottom = tzc::json::getFiled(document, "bottom", 0.0f);
- value.confidence = tzc::json::getFiled(document, "confidence", 0.0f);
- return TRUE;
- }
- };
- struct YoloCrowdDetectResult{
-
- std::vector<DetObj> objs;
-
- std::string toJson() const
- {
- tzc::json::JsonDoc document;
- document.SetObject();
-
- tzc::json::setFiledArrayObject(document, "objs", objs);
-
- return tzc::json::ValueToJson(document);
- }
-
- static TZ_BOOL fromJson(const std::string& json, YoloCrowdDetectResult& value)
- {
- tzc::json::JsonDoc document;
- document.Parse(json.c_str());
- if(document.HasParseError())
- {
- return FALSE;
- }
-
- TZ_BOOL rst = TRUE;
- rst &= tzc::json::ConverArrayObject(document, "objs", value.objs);
-
- return rst;
- }
- };
- NAMESPACE_YOLOCROWD_END
- NAMESPACE_MAS_END
- #endif
|