From 5d36dfd283d60dc6fcda4b97adcce7153f36c27f Mon Sep 17 00:00:00 2001 From: zhuxc Date: Mon, 11 Dec 2023 18:49:14 +0800 Subject: [PATCH] fix: fix opencv_contrib issue #2941 --- modules/cudabgsegm/src/mog2.cpp | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/modules/cudabgsegm/src/mog2.cpp b/modules/cudabgsegm/src/mog2.cpp index 47135a088b..719317014a 100644 --- a/modules/cudabgsegm/src/mog2.cpp +++ b/modules/cudabgsegm/src/mog2.cpp @@ -105,10 +105,21 @@ class MOG2Impl CV_FINAL : public cuda::BackgroundSubtractorMOG2 void setVarInit(double varInit) CV_OVERRIDE { constantsHost_.varInit_ = (float)varInit; } double getVarMin() const CV_OVERRIDE { return constantsHost_.varMin_; } - void setVarMin(double varMin) CV_OVERRIDE { constantsHost_.varMin_ = ::fminf((float)varMin, constantsHost_.varMax_); } - + void setVarMin(double varMin) CV_OVERRIDE { + if (nframes_ == 0) { + constantsHost_.varMin_ = (float)varMin; + } else { + constantsHost_.varMin_ = ::fminf((float)varMin, constantsHost_.varMax_); + } + } double getVarMax() const CV_OVERRIDE { return constantsHost_.varMax_; } - void setVarMax(double varMax) CV_OVERRIDE { constantsHost_.varMax_ = ::fmaxf(constantsHost_.varMin_, (float)varMax); } + void setVarMax(double varMax) CV_OVERRIDE { + if (nframes_ == 0) { + constantsHost_.varMax_ = (float)varMax; + } else { + constantsHost_.varMax_ = ::fmaxf(constantsHost_.varMin_, (float)varMax); + } + } double getComplexityReductionThreshold() const CV_OVERRIDE { return ct_; } void setComplexityReductionThreshold(double ct) CV_OVERRIDE { ct_ = (float)ct; }