@@ -623,9 +623,8 @@ void cls_alg::diff_nomask()
623623
624624 int i, curdiff;
625625 int imgsz = cam->imgs .motionsize ;
626- int diffs = 0 , diffs_net = 0 ;
626+ int diffs = 0 ;
627627 int noise = cam->noise ;
628- int lrgchg = cam->cfg ->threshold_ratio_change ;
629628
630629 memset (out + imgsz, 128 , (uint)(imgsz / 2 ));
631630 memset (out, 0 , (uint)imgsz);
@@ -635,11 +634,6 @@ void cls_alg::diff_nomask()
635634 if (abs (curdiff) > noise) {
636635 *out = *new_img;
637636 diffs++;
638- if (curdiff > lrgchg) {
639- diffs_net++;
640- } else if (curdiff < -lrgchg) {
641- diffs_net--;
642- }
643637 }
644638 out++;
645639 ref++;
@@ -649,12 +643,6 @@ void cls_alg::diff_nomask()
649643 cam->current_image ->diffs = diffs;
650644 cam->imgs .image_motion .imgts = cam->current_image ->imgts ;
651645
652- if (diffs > 0 ) {
653- cam->current_image ->diffs_ratio = (abs (diffs_net) * 100 ) / diffs;
654- } else {
655- cam->current_image ->diffs_ratio = 100 ;
656- }
657-
658646}
659647
660648void cls_alg::diff_mask ()
@@ -666,9 +654,8 @@ void cls_alg::diff_mask()
666654
667655 int i, curdiff;
668656 int imgsz = cam->imgs .motionsize ;
669- int diffs = 0 , diffs_net = 0 ;
657+ int diffs = 0 ;
670658 int noise = cam->noise ;
671- int lrgchg = cam->cfg ->threshold_ratio_change ;
672659
673660 memset (out + imgsz, 128 , (uint)(imgsz / 2 ));
674661 memset (out, 0 , (uint)imgsz);
@@ -682,11 +669,6 @@ void cls_alg::diff_mask()
682669 if (abs (curdiff) > noise) {
683670 *out = *new_img;
684671 diffs++;
685- if (curdiff > lrgchg) {
686- diffs_net++;
687- } else if (curdiff < -lrgchg) {
688- diffs_net--;
689- }
690672 }
691673
692674 out++;
@@ -698,12 +680,6 @@ void cls_alg::diff_mask()
698680 cam->current_image ->diffs = diffs;
699681 cam->imgs .image_motion .imgts = cam->current_image ->imgts ;
700682
701- if (diffs > 0 ) {
702- cam->current_image ->diffs_ratio = (abs (diffs_net) * 100 ) / diffs;
703- } else {
704- cam->current_image ->diffs_ratio = 100 ;
705- }
706-
707683}
708684
709685void cls_alg::diff_smart ()
@@ -716,10 +692,9 @@ void cls_alg::diff_smart()
716692
717693 int i, curdiff;
718694 int imgsz = cam->imgs .motionsize ;
719- int diffs = 0 , diffs_net = 0 ;
695+ int diffs = 0 ;
720696 int noise = cam->noise ;
721697 int *mask_buffer = smartmask_buffer;
722- int lrgchg = cam->cfg ->threshold_ratio_change ;
723698
724699 imgsz = cam->imgs .motionsize ;
725700 memset (out + imgsz, 128 , (uint)(imgsz / 2 ));
@@ -743,11 +718,6 @@ void cls_alg::diff_smart()
743718 if (abs (curdiff) > noise) {
744719 *out = *new_img;
745720 diffs++;
746- if (curdiff > lrgchg) {
747- diffs_net++;
748- } else if (curdiff < -lrgchg) {
749- diffs_net--;
750- }
751721 }
752722 out++;
753723 ref++;
@@ -757,11 +727,6 @@ void cls_alg::diff_smart()
757727 cam->current_image ->diffs = diffs;
758728 cam->imgs .image_motion .imgts = cam->current_image ->imgts ;
759729
760- if (diffs > 0 ) {
761- cam->current_image ->diffs_ratio = (abs (diffs_net) * 100 ) / diffs;
762- } else {
763- cam->current_image ->diffs_ratio = 100 ;
764- }
765730}
766731
767732void cls_alg::diff_masksmart ()
@@ -774,10 +739,9 @@ void cls_alg::diff_masksmart()
774739
775740 int i, curdiff;
776741 int imgsz = cam->imgs .motionsize ;
777- int diffs = 0 , diffs_net = 0 ;
742+ int diffs = 0 ;
778743 int noise = cam->noise ;
779744 int *mask_buffer = smartmask_buffer;
780- int lrgchg = cam->cfg ->threshold_ratio_change ;
781745
782746 imgsz= cam->imgs .motionsize ;
783747 memset (out + imgsz, 128 , ((uint)imgsz / 2 ));
@@ -806,11 +770,6 @@ void cls_alg::diff_masksmart()
806770 if (abs (curdiff) > noise) {
807771 *out = *new_img;
808772 diffs++;
809- if (curdiff > lrgchg) {
810- diffs_net++;
811- } else if (curdiff < -lrgchg) {
812- diffs_net--;
813- }
814773 }
815774
816775 out++;
@@ -823,12 +782,6 @@ void cls_alg::diff_masksmart()
823782 cam->current_image ->diffs = diffs;
824783 cam->imgs .image_motion .imgts = cam->current_image ->imgts ;
825784
826- if (diffs > 0 ) {
827- cam->current_image ->diffs_ratio = (abs (diffs_net) * 100 ) / diffs;
828- } else {
829- cam->current_image ->diffs_ratio = 100 ;
830- }
831-
832785}
833786
834787bool cls_alg::diff_fast ()
@@ -989,85 +942,7 @@ void cls_alg::location_center()
989942
990943}
991944
992- /* Calculate distribution and variances of changes*/
993- void cls_alg::location_dist_stddev ()
994- {
995- ctx_images *imgs = &cam->imgs ;
996- int width = cam->imgs .width ;
997- int height = cam->imgs .height ;
998- ctx_coord *cent = &cam->current_image ->location ;
999- u_char *out = imgs->image_motion .image_norm ;
1000- int x, y, centc = 0 , xdist = 0 , ydist = 0 ;
1001- int64_t variance_x, variance_y, variance_xy, distance_mean;
1002-
1003- cent->maxx = 0 ;
1004- cent->maxy = 0 ;
1005- cent->minx = width;
1006- cent->miny = height;
1007- variance_x = 0 ;
1008- variance_y = 0 ;
1009- distance_mean = 0 ;
1010-
1011- for (y = 0 ; y < height; y++) {
1012- for (x = 0 ; x < width; x++) {
1013- if (*(out++)) {
1014- variance_x += ((x - cent->x ) * (x - cent->x ));
1015- variance_y += ((y - cent->y ) * (y - cent->y ));
1016- distance_mean += (int64_t )sqrt (
1017- ((x - cent->x ) * (x - cent->x )) +
1018- ((y - cent->y ) * (y - cent->y )));
1019-
1020- if (x > cent->x ) {
1021- xdist += x - cent->x ;
1022- } else if (x < cent->x ) {
1023- xdist += cent->x - x;
1024- }
1025-
1026- if (y > cent->y ) {
1027- ydist += y - cent->y ;
1028- } else if (y < cent->y ) {
1029- ydist += cent->y - y;
1030- }
1031-
1032- centc++;
1033- }
1034- }
1035- }
1036-
1037- if (centc) {
1038- cent->minx = cent->x - xdist / centc * 3 ;
1039- cent->maxx = cent->x + xdist / centc * 3 ;
1040- cent->miny = cent->y - ydist / centc * 3 ;
1041- cent->maxy = cent->y + ydist / centc * 3 ;
1042- cent->stddev_x = (int )sqrt ((variance_x / centc));
1043- cent->stddev_y = (int )sqrt ((variance_y / centc));
1044- distance_mean = (int64_t )(distance_mean / centc);
1045- } else {
1046- cent->stddev_y = 0 ;
1047- cent->stddev_x = 0 ;
1048- distance_mean = 0 ;
1049- }
1050-
1051- variance_xy = 0 ;
1052- out = imgs->image_motion .image_norm ;
1053- for (y = 0 ; y < height; y++) {
1054- for (x = 0 ; x < width; x++) {
1055- if (*(out++)) {
1056- variance_xy += (
1057- ((int64_t )sqrt (((x - cent->x ) * (x - cent->x )) +
1058- ((y - cent->y ) * (y - cent->y ))) - distance_mean) *
1059- ((int64_t )sqrt (((x - cent->x ) * (x - cent->x )) +
1060- ((y - cent->y ) * (y - cent->y ))) - distance_mean));
1061- }
1062- }
1063- }
1064- /* Per statistics, divide by n-1 for calc of a standard deviation */
1065- if ((centc-1 ) > 0 ) {
1066- cent->stddev_xy = (int )sqrt ((variance_xy / (centc-1 )));
1067- }
1068- }
1069-
1070- void cls_alg::location_dist_basic ()
945+ void cls_alg::location_dist ()
1071946{
1072947 ctx_images *imgs = &cam->imgs ;
1073948 int width = cam->imgs .width ;
@@ -1106,9 +981,6 @@ void cls_alg::location_dist_basic()
1106981 cent->maxx = cent->x + xdist / centc * 3 ;
1107982 cent->miny = cent->y - ydist / centc * 3 ;
1108983 cent->maxy = cent->y + ydist / centc * 3 ;
1109- } else {
1110- cent->stddev_y = 0 ;
1111- cent->stddev_x = 0 ;
1112984 }
1113985}
1114986
@@ -1159,38 +1031,10 @@ void cls_alg::location_minmax()
11591031void cls_alg::location ()
11601032{
11611033 location_center ();
1162- if (calc_stddev) {
1163- location_dist_stddev ();
1164- } else {
1165- location_dist_basic ();
1166- }
1034+ location_dist ();
11671035 location_minmax ();
11681036}
11691037
1170- /* Apply user or default thresholds on standard deviations*/
1171- void cls_alg::stddev ()
1172- {
1173- if (calc_stddev == false ) {
1174- return ;
1175- }
1176- if (cam->cfg ->threshold_sdevx > 0 ) {
1177- if (cam->current_image ->location .stddev_x > cam->cfg ->threshold_sdevx ) {
1178- cam->current_image ->diffs = 0 ;
1179- return ;
1180- }
1181- } else if (cam->cfg ->threshold_sdevy > 0 ) {
1182- if (cam->current_image ->location .stddev_y > cam->cfg ->threshold_sdevy ) {
1183- cam->current_image ->diffs = 0 ;
1184- return ;
1185- }
1186- } else if (cam->cfg ->threshold_sdevxy > 0 ) {
1187- if (cam->current_image ->location .stddev_xy > cam->cfg ->threshold_sdevxy ) {
1188- cam->current_image ->diffs = 0 ;
1189- return ;
1190- }
1191- }
1192- }
1193-
11941038void cls_alg::diff ()
11951039{
11961040 if (cam->detecting_motion ) {
@@ -1201,7 +1045,6 @@ void cls_alg::diff()
12011045 } else {
12021046 cam->current_image ->diffs = 0 ;
12031047 cam->current_image ->diffs_raw = 0 ;
1204- cam->current_image ->diffs_ratio = 100 ;
12051048 }
12061049 }
12071050 lightswitch ();
@@ -1214,14 +1057,6 @@ cls_alg::cls_alg(cls_camera *p_cam)
12141057
12151058 cam = p_cam;
12161059
1217- if ((cam->cfg ->threshold_sdevx == 0 ) &&
1218- (cam->cfg ->threshold_sdevy == 0 ) &&
1219- (cam->cfg ->threshold_sdevxy == 0 )) {
1220- calc_stddev = false ;
1221- } else {
1222- calc_stddev = true ;
1223- }
1224-
12251060 smartmask =(unsigned char *) mymalloc ((uint)cam->imgs .motionsize );
12261061 smartmask_final =(unsigned char *) mymalloc ((uint)cam->imgs .motionsize );
12271062 smartmask_buffer =(int *) mymalloc ((uint)cam->imgs .motionsize * sizeof (*smartmask_buffer));
0 commit comments