diff --git a/src/alg_sec.cpp b/src/alg_sec.cpp index 30ae9fba..7fb1390e 100644 --- a/src/alg_sec.cpp +++ b/src/alg_sec.cpp @@ -216,7 +216,7 @@ static void algsec_detect_hog(ctx_cam *cam, ctx_algsec_model &algmdl) const char* err_msg = e.what(); MOTION_LOG(ERR, TYPE_ALL, NO_ERRNO, _("Error %s"),err_msg); MOTION_LOG(ERR, TYPE_ALL, NO_ERRNO, _("Disabling secondary detection")); - algmdl.method = 0; + algmdl.method = "none"; } } @@ -265,7 +265,7 @@ static void algsec_detect_haar(ctx_cam *cam, ctx_algsec_model &algmdl) const char* err_msg = e.what(); MOTION_LOG(ERR, TYPE_ALL, NO_ERRNO, _("Error %s"),err_msg); MOTION_LOG(ERR, TYPE_ALL, NO_ERRNO, _("Disabling secondary detection")); - algmdl.method = 0; + algmdl.method = "none"; } } @@ -274,13 +274,13 @@ static void algsec_load_haar(ctx_algsec_model &algmdl) /* If loading fails, reset the method to invalidate detection */ try { if (algmdl.model_file == "") { - algmdl.method = 0; + algmdl.method = "none"; MOTION_LOG(ERR, TYPE_ALL, NO_ERRNO, _("No secondary model specified.")); return; } if (!algmdl.haar_cascade.load(algmdl.model_file)) { /* Loading failed, reset method*/ - algmdl.method = 0; + algmdl.method = "none"; MOTION_LOG(ERR, TYPE_ALL, NO_ERRNO, _("Failed loading model %s") ,algmdl.model_file.c_str()); }; @@ -288,7 +288,7 @@ static void algsec_load_haar(ctx_algsec_model &algmdl) const char* err_msg = e.what(); MOTION_LOG(ERR, TYPE_ALL, NO_ERRNO, _("Error %s"),err_msg); MOTION_LOG(ERR, TYPE_ALL, NO_ERRNO, _("Failed loading model %s"), algmdl.model_file.c_str()); - algmdl.method = 0; + algmdl.method = "none"; } } @@ -363,7 +363,7 @@ static void algsec_params_defaults(ctx_algsec_model &algmdl) util_parms_add_default(algmdl.algsec_params, "imagetype", "full"); util_parms_add_default(algmdl.algsec_params, "threshold_motion", "1.1"); - if (algmdl.method == 1) { + if (algmdl.method == "haar") { util_parms_add_default(algmdl.algsec_params, "threshold_model", "1.4"); util_parms_add_default(algmdl.algsec_params, "scalefactor", "1.1"); } else { @@ -437,21 +437,16 @@ static int algsec_load_params(ctx_cam *cam) static int algsec_load_models(ctx_cam *cam) { - if (cam->algsec->models.method != 0){ - switch (cam->algsec->models.method) { - case 1: //Haar Method - algsec_load_haar(cam->algsec->models); - break; - case 2: //HoG Method - //algsec_load_hog(cam->algsec->models); - break; - default: - cam->algsec->models.method = 0; - } + if (cam->algsec->models.method == "haar") { + algsec_load_haar(cam->algsec->models); + } else if (cam->algsec->models.method == "hog") { + //algsec_load_hog(cam->algsec->models); + } else { + cam->algsec->models.method = "none"; } - /* If model fails to load, it sets method to zero*/ - if (cam->algsec->models.method != 0){ + /* If model fails to load, the method is changed to none*/ + if (cam->algsec->models.method != "none"){ cam->algsec_inuse = true; return 0; } else { @@ -475,13 +470,10 @@ static void *algsec_handler(void *arg) while (!cam->algsec->closing){ if (cam->algsec->detecting){ - switch (cam->algsec->models.method) { - case 1: //Haar Method + if (cam->algsec->models.method == "haar") { algsec_detect_haar(cam, cam->algsec->models); - break; - case 2: //HoG Method + } else if (cam->algsec->models.method == "hog") { algsec_detect_hog(cam, cam->algsec->models); - break; } cam->algsec->detecting = false; /*Set the event based isdetected bool */ @@ -511,7 +503,7 @@ static void algsec_start_handler(ctx_cam *cam) if (retcd < 0) { MOTION_LOG(ALR, TYPE_NETCAM, SHOW_ERRNO ,_("Error starting algsec handler thread")); - cam->algsec->models.method = 0; + cam->algsec->models.method = "none"; } pthread_attr_destroy(&handler_attribute); return; diff --git a/src/alg_sec.hpp b/src/alg_sec.hpp index 40a74b2a..74651912 100644 --- a/src/alg_sec.hpp +++ b/src/alg_sec.hpp @@ -39,7 +39,7 @@ struct ctx_algsec_model { std::string model_file; int frame_interval; - int method; + std::string method; std::string imagetype; int rotate; diff --git a/src/conf.cpp b/src/conf.cpp index 0a85136c..62f8b43a 100644 --- a/src/conf.cpp +++ b/src/conf.cpp @@ -90,7 +90,7 @@ struct ctx_parm config_parms[] = { {"threshold_ratio_change", PARM_TYP_INT, PARM_CAT_05, WEBUI_LEVEL_LIMITED }, {"threshold_tune", PARM_TYP_BOOL, PARM_CAT_05, WEBUI_LEVEL_LIMITED }, {"secondary_interval", PARM_TYP_INT, PARM_CAT_05, WEBUI_LEVEL_LIMITED }, - {"secondary_method", PARM_TYP_INT, PARM_CAT_05, WEBUI_LEVEL_LIMITED }, + {"secondary_method", PARM_TYP_LIST, PARM_CAT_05, WEBUI_LEVEL_LIMITED }, {"secondary_params", PARM_TYP_STRING, PARM_CAT_05, WEBUI_LEVEL_LIMITED }, {"noise_level", PARM_TYP_INT, PARM_CAT_06, WEBUI_LEVEL_LIMITED }, @@ -1242,18 +1242,21 @@ static void conf_edit_secondary_interval(struct ctx_cam *cam, std::string &parm, static void conf_edit_secondary_method(struct ctx_cam *cam, std::string &parm, enum PARM_ACT pact) { - int parm_in; if (pact == PARM_ACT_DFLT) { - cam->conf->secondary_method = 0; + cam->conf->secondary_method = "none"; } else if (pact == PARM_ACT_SET) { - parm_in = atoi(parm.c_str()); - if ((parm_in < 0) ) { - MOTION_LOG(NTC, TYPE_ALL, NO_ERRNO, _("Invalid secondary_method %d"),parm_in); + if ((parm == "none") || (parm == "haar") || + (parm == "hog")) { + cam->conf->secondary_method = parm; + } else if (parm == "") { + cam->conf->secondary_method = "none"; } else { - cam->conf->secondary_method = parm_in; + MOTION_LOG(NTC, TYPE_ALL, NO_ERRNO, _("Invalid secondary_method %s"), parm.c_str()); } } else if (pact == PARM_ACT_GET) { - parm = std::to_string(cam->conf->secondary_method); + parm = cam->conf->secondary_method; + } else if (pact == PARM_ACT_LIST) { + parm = "[\"none\",\"haar\",\"hog\"]"; } return; MOTION_LOG(DBG, TYPE_ALL, NO_ERRNO,"%s:%s","secondary_method",_("secondary_method")); diff --git a/src/conf.hpp b/src/conf.hpp index 96e91efd..3b32daf3 100644 --- a/src/conf.hpp +++ b/src/conf.hpp @@ -73,7 +73,7 @@ int threshold_ratio_change; bool threshold_tune; int secondary_interval; - int secondary_method; + std::string secondary_method; std::string secondary_params; int noise_level; bool noise_tune;