Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,13 @@
#include <cmath>
#include <vector>

const double MSE_THRESH = 20.0;
const double SSIM_THRESH = 0.998;
const double FLOW_THRESH = 0.5;
const double OPTICAL_FLOW_ACTIVE_THRESH = 0.5;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great that you wrote them as constants, but please remove the initialization from the constructor or use these constants as the initial values there.


GPUFrameChangeDetector::GPUFrameChangeDetector()
: mse_thresh(500.0), ssim_thresh(0.99), flow_thresh(2.0), initialized(true) {}
: mse_thresh(MSE_THRESH), ssim_thresh(SSIM_THRESH), flow_thresh(FLOW_THRESH), initialized(true) {}

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

cv::cuda::GpuMat active_mask;
cv::cuda::threshold(mag, active_mask, 0.5, 1.0, cv::THRESH_BINARY);
cv::cuda::threshold(mag, active_mask, OPTICAL_FLOW_ACTIVE_THRESH, 1.0, cv::THRESH_BINARY);

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

bool is_static = (mse_val < 10.0 && ssim_val > 0.995 && flow_val < 0.05);
bool is_static = (mse_val < mse_thresh && ssim_val > ssim_thresh && flow_val < flow_thresh);

bool should_proc = !is_static;
if (should_proc) {
Expand Down
Binary file not shown.
Loading