Skip to content

Commit 05fa9db

Browse files
authored
update the threshold values (#170)
* update the threshold values * Refactor: applied named constants (MSE, SSIM, FLOW thresholds) in constructor init
1 parent bf022cb commit 05fa9db

File tree

2 files changed

+7
-3
lines changed

2 files changed

+7
-3
lines changed

src/deepstream/probes/frame_comparison/gpu/frame_change_detector.cpp

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,13 @@
55
#include <cmath>
66
#include <vector>
77

8+
const double MSE_THRESH = 20.0;
9+
const double SSIM_THRESH = 0.998;
10+
const double FLOW_THRESH = 0.5;
11+
const double OPTICAL_FLOW_ACTIVE_THRESH = 0.5;
812

913
GPUFrameChangeDetector::GPUFrameChangeDetector()
10-
: mse_thresh(500.0), ssim_thresh(0.99), flow_thresh(2.0), initialized(true) {}
14+
: mse_thresh(MSE_THRESH), ssim_thresh(SSIM_THRESH), flow_thresh(FLOW_THRESH), initialized(true) {}
1115

1216
static cv::Scalar mean_gpu(const cv::cuda::GpuMat& mat) {
1317
cv::Scalar sum_val = cv::cuda::sum(mat);
@@ -80,7 +84,7 @@ double GPUFrameChangeDetector::optical_flow_gpu(const cv::cuda::GpuMat& imgA, co
8084
cv::cuda::cartToPolar(flow_xy[0], flow_xy[1], mag, angle, true);
8185

8286
cv::cuda::GpuMat active_mask;
83-
cv::cuda::threshold(mag, active_mask, 0.5, 1.0, cv::THRESH_BINARY);
87+
cv::cuda::threshold(mag, active_mask, OPTICAL_FLOW_ACTIVE_THRESH, 1.0, cv::THRESH_BINARY);
8488

8589
cv::cuda::GpuMat active_pixels;
8690
mag.copyTo(active_pixels, active_mask);
@@ -108,7 +112,7 @@ GPUFrameChangeDetector::should_process_gpu_direct(const cv::cuda::GpuMat& gpu_fr
108112
double ssim_val = simple_ssim_gpu(prev_frame_gpu, processed_curr);
109113
double flow_val = optical_flow_gpu(prev_frame_gpu, processed_curr);
110114

111-
bool is_static = (mse_val < 10.0 && ssim_val > 0.995 && flow_val < 0.05);
115+
bool is_static = (mse_val < mse_thresh && ssim_val > ssim_thresh && flow_val < flow_thresh);
112116

113117
bool should_proc = !is_static;
114118
if (should_proc) {
Binary file not shown.

0 commit comments

Comments
 (0)