From 0eb2a49e1ad51e960fa421050dda2219ebfcbb63 Mon Sep 17 00:00:00 2001 From: MrDave Date: Sun, 20 Oct 2019 15:13:38 -0600 Subject: [PATCH] Refine stream for secondary --- src/alg_sec.cpp | 52 ++++++++++++++++++++++++--------------------- src/motion.hpp | 2 ++ src/motion_loop.cpp | 2 +- src/webu.cpp | 6 +++++- 4 files changed, 36 insertions(+), 26 deletions(-) diff --git a/src/alg_sec.cpp b/src/alg_sec.cpp index 99bff5d0..fa3d8e95 100644 --- a/src/alg_sec.cpp +++ b/src/alg_sec.cpp @@ -69,15 +69,16 @@ static void algsec_img_show(ctx_cam *cam, Mat &mat_src putText(mat_src, wstr, Point(r.x,r.y), FONT_HERSHEY_SIMPLEX, 1, 255, 2); } imwrite(testdir + "/detect_" + algmethod + ".jpg", mat_src); - param[0] = cv::IMWRITE_JPEG_QUALITY; - param[1] = 75; - cv::imencode(".jpg", mat_src, buff, param); - pthread_mutex_lock(&cam->algsec->mutex); - std::copy(buff.begin(), buff.end(), cam->imgs.image_secondary); - cam->imgs.size_secondary = (int)buff.size(); - pthread_mutex_unlock(&cam->algsec->mutex); } + param[0] = cv::IMWRITE_JPEG_QUALITY; + param[1] = 75; + cv::imencode(".jpg", mat_src, buff, param); + pthread_mutex_lock(&cam->algsec->mutex); + std::copy(buff.begin(), buff.end(), cam->imgs.image_secondary); + cam->imgs.size_secondary = (int)buff.size(); + pthread_mutex_unlock(&cam->algsec->mutex); + } static void algsec_img_roi(ctx_cam *cam, Mat &mat_src, Mat &mat_dst){ @@ -172,9 +173,9 @@ static void algsec_detect_hog(ctx_cam *cam, ctx_algsec_model &algmdl){ ,false); MOTION_LOG(INF, TYPE_ALL, NO_ERRNO - , _("HOG Parmeters: winstride %d,%d padding %d,%d scale %.2f theshold %d") - ,Size(algmdl.parms_int[0][2], algmdl.parms_int[0][2]) - ,Size(algmdl.parms_int[0][3], algmdl.parms_int[0][3]) + , _("Parms: winstride %d,%d padding %d,%d scale %.2f theshold %d") + ,algmdl.parms_int[0][2], algmdl.parms_int[0][2] + ,algmdl.parms_int[0][3], algmdl.parms_int[0][3] ,algmdl.parms_float[0][4] ,algmdl.parms_int[0][5]); @@ -215,9 +216,9 @@ static void algsec_detect_haar(ctx_cam *cam, ctx_algsec_model &algmdl){ } } -static void algsec_load_yolo(ctx_algsec_model &algsec){ +static void algsec_load_yolo(ctx_algsec_model &algmdl){ /* Placeholder for implementation of yolo classifier */ - (void)algsec; + algmdl.method = 0; } @@ -399,16 +400,10 @@ static void algsec_load_parms(ctx_cam *cam){ /**If possible preload the models and initialize them */ static int algsec_load_models(ctx_cam *cam){ - int indx, retcd; - /* Default the return code to no models found. If after looping - * through and loading the models, we have a method, then we set - * the return code to ok (zero). If a model fails to load then - * in that function we reset the method to zero. - */ - retcd = -1; + int indx; + for (indx=0;indx<3;indx++){ if (cam->algsec->models[indx].method != 0){ - retcd = 0; switch (cam->algsec->models[indx].method) { case 1: //Haar Method algsec_load_haar(cam->algsec->models[indx]); @@ -418,11 +413,20 @@ static int algsec_load_models(ctx_cam *cam){ case 3: //YoLo Method algsec_load_yolo(cam->algsec->models[indx]); break; + default: + cam->algsec->models[indx].method = 0; } } } - return retcd; + /* If model fails to load, it sets method to zero*/ + if (cam->algsec->models[0].method != 0){ + cam->algsec_inuse = TRUE; + return 0; + } else { + cam->algsec_inuse = FALSE; + return -1; + } } @@ -523,8 +527,8 @@ void algsec_deinit(ctx_cam *cam){ if (!cam->algsec->closing) { cam->algsec->closing = true; - while ((cam->algsec->closing) && (waitcnt <100)){ - SLEEP(0,1000000) + while ((cam->algsec->closing) && (waitcnt <1000)){ + SLEEP(0,100000) waitcnt++; } } @@ -532,7 +536,7 @@ void algsec_deinit(ctx_cam *cam){ free(cam->algsec->image_norm); cam->algsec->image_norm = nullptr; } - if (waitcnt == 100){ + if (waitcnt == 1000){ MOTION_LOG(ERR, TYPE_NETCAM, NO_ERRNO ,_("Graceful shutdown of secondary detector thread failed")); } diff --git a/src/motion.hpp b/src/motion.hpp index 17daf02e..44f9dcf4 100644 --- a/src/motion.hpp +++ b/src/motion.hpp @@ -328,6 +328,7 @@ struct ctx_cam { struct ctx_movie *movie_timelapse; struct ctx_stream stream; + int algsec_inuse; /*Bool for whether we have secondary detection*/ int track_posx; int track_posy; int camera_id; @@ -400,6 +401,7 @@ struct ctx_cam { int previous_diffs, previous_location_x, previous_location_y; unsigned int passflag; //only purpose is to flag first frame vs all others..... + }; /* ctx_cam for whole motion application including all the cameras */ diff --git a/src/motion_loop.cpp b/src/motion_loop.cpp index 73b8d598..44d629c4 100644 --- a/src/motion_loop.cpp +++ b/src/motion_loop.cpp @@ -399,7 +399,7 @@ static void mlp_init_values(struct ctx_cam *cam) { cam->event_user = FALSE; cam->event_stop = FALSE; cam->passflag = FALSE; //only purpose to flag first frame - + cam->algsec_inuse = FALSE; /* Make sure to default the high res to zero */ cam->imgs.width_high = 0; diff --git a/src/webu.cpp b/src/webu.cpp index fc4cb1c7..0b8c86ca 100644 --- a/src/webu.cpp +++ b/src/webu.cpp @@ -1186,7 +1186,11 @@ static void webu_answer_strm_type(struct webui_ctx *webui) { } else if ((mystreq(webui->uri_cmd1,"secondary")) || (mystreq(webui->uri_camid,"secondary"))){ - webui->cnct_type = WEBUI_CNCT_SECONDARY; + if (webui->cam->algsec_inuse) { + webui->cnct_type = WEBUI_CNCT_SECONDARY; + } else { + webui->cnct_type = WEBUI_CNCT_UNKNOWN; + } } else if ((mystreq(webui->uri_cmd1,"current")) || (mystreq(webui->uri_camid,"current"))){