Skip to content

Commit 39bd063

Browse files
committed
Remove standard deviation computations
1 parent 2e325a7 commit 39bd063

12 files changed

Lines changed: 13 additions & 431 deletions

File tree

doc/motion_config.html

Lines changed: 3 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -254,37 +254,27 @@ <h2><a name="Configuration_OptionsTopic"></a> Configuration Options-Listed by T
254254
<td bgcolor="#edf4f9" ><a href="#threshold_tune" >threshold_tune</a> </td>
255255
</tr>
256256
<tr>
257-
<td bgcolor="#edf4f9" ><a href="#threshold_sdevx" >threshold_sdevx</a> </td>
258-
<td bgcolor="#edf4f9" ><a href="#threshold_sdevy" >threshold_sdevy</a> </td>
259-
<td bgcolor="#edf4f9" ><a href="#threshold_sdevxy" >threshold_sdevxy</a> </td>
260-
<td bgcolor="#edf4f9" ><a href="#threshold_ratio" >threshold_tune</a> </td>
261-
</tr>
262-
<tr>
263-
<td bgcolor="#edf4f9" ><a href="#threshold_ratio_change" >threshold_ratio_change</a> </td>
264257
<td bgcolor="#edf4f9" ><a href="#secondary_method" >secondary_method</a> </td>
265258
<td bgcolor="#edf4f9" ><a href="#secondary_params" >secondary_params</a> </td>
266259
<td bgcolor="#edf4f9" ><a href="#noise_level" >noise_level</a> </td>
260+
<td bgcolor="#edf4f9" ><a href="#noise_tune" >noise_tune</a> </td>
267261
</tr>
268-
269262
<tr>
270-
<td bgcolor="#edf4f9" ><a href="#noise_tune" >noise_tune</a> </td>
271263
<td bgcolor="#edf4f9" ><a href="#despeckle_filter" >despeckle_filter</a> </td>
272264
<td bgcolor="#edf4f9" ><a href="#area_detect" >area_detect</a> </td>
273265
<td bgcolor="#edf4f9" ><a href="#mask_file" >mask_file</a> </td>
266+
<td bgcolor="#edf4f9" ><a href="#mask_privacy" >mask_privacy</a> </td>
274267
</tr>
275268
<tr>
276-
<td bgcolor="#edf4f9" ><a href="#mask_privacy" >mask_privacy</a> </td>
277269
<td bgcolor="#edf4f9" ><a href="#smart_mask_speed" >smart_mask_speed</a> </td>
278270
<td bgcolor="#edf4f9" ><a href="#lightswitch_percent" >lightswitch_percent</a> </td>
279271
<td bgcolor="#edf4f9" ><a href="#lightswitch_frames" >lightswitch_frames</a> </td>
272+
<td bgcolor="#edf4f9" ><a href="#minimum_motion_frames" >minimum_motion_frames</a> </td>
280273
</tr>
281274
<tr>
282-
<td bgcolor="#edf4f9" ><a href="#minimum_motion_frames" >minimum_motion_frames</a> </td>
283275
<td bgcolor="#edf4f9" ><a href="#event_gap" >event_gap</a> </td>
284276
<td bgcolor="#edf4f9" ><a href="#pre_capture" >pre_capture</a> </td>
285277
<td bgcolor="#edf4f9" ><a href="#post_capture" >post_capture</a> </td>
286-
</tr>
287-
<tr>
288278
<td bgcolor="#edf4f9" ><a href="#static_object_time" >static_object_time</a> </td>
289279
</tr>
290280
</tbody>
@@ -1687,42 +1677,6 @@ <h3><a name="threshold_tune"></a> threshold_tune </h3>
16871677
</ul>
16881678
<p></p>
16891679

1690-
1691-
<h3><a name="threshold_sdevx"></a>threshold_sdevx</h3>
1692-
<ul>
1693-
<li> Values: Integer | Default: 0</li>
1694-
The maximum standard deviation of the changed pixels in the x (width) axis.
1695-
</ul>
1696-
<p></p>
1697-
1698-
<h3><a name="threshold_sdevy"></a>threshold_sdevy</h3>
1699-
<ul>
1700-
<li> Values: Integer | Default: 0</li>
1701-
The maximum standard deviation of the changed pixels in the y (height) axis.
1702-
</ul>
1703-
<p></p>
1704-
1705-
<h3><a name="threshold_sdevxy"></a>threshold_sdevxy</h3>
1706-
<ul>
1707-
<li> Values: Integer | Default: 0</li>
1708-
The maximum standard deviation of the changed pixels in the x (width) and y(height) axis.
1709-
</ul>
1710-
<p></p>
1711-
1712-
<h3><a name="threshold_ratio"></a>threshold_ratio</h3>
1713-
<ul>
1714-
<li> Values: Integer | Default: </li>
1715-
The maximum ratio comparing the pixels that went white to black and vice versa.
1716-
</ul>
1717-
<p></p>
1718-
1719-
<h3><a name="threshold_ratio_change"></a>threshold_ratio_change</h3>
1720-
<ul>
1721-
<li> Values: Integer | Default: </li>
1722-
The minimum change in the ratio to trigger a event.
1723-
</ul>
1724-
<p></p>
1725-
17261680
<h3><a name="secondary_method"></a>secondary_method</h3>
17271681
<ul>
17281682
<li> Values: haar, hog, dnn | Default: Not Defined</li>

src/alg.cpp

Lines changed: 6 additions & 171 deletions
Original file line numberDiff line numberDiff line change
@@ -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

660648
void 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

709685
void 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

767732
void 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

834787
bool 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()
11591031
void 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-
11941038
void 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

Comments
 (0)