Skip to content

fix: fix opencv_contrib issue #2941 #3606

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: 4.x
Choose a base branch
from
Open
Changes from 2 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
17 changes: 14 additions & 3 deletions modules/cudabgsegm/src/mog2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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_);

Choose a reason for hiding this comment

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

It is still buggy. Bug is in API itself.

Good API should configure min/max at once through single call (using cv::Range).

Or setting min should set the min and adjust the MAX value (instead of min).

Copy link
Contributor Author

@Chester-zZz Chester-zZz Apr 19, 2024

Choose a reason for hiding this comment

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

Got it. Since constantsHost_ will be upload to gpu in initialize, i can just compare them in initialize. and keep the setVarXXX method simple.

float real_varMin = ::fminf(constantsHost_.varMin_, constantsHost_.varMax_);
float real_varMax = ::fmaxf(constantsHost_.varMin_, constantsHost_.varMax_);
constantsHost_.varMin_ = real_varMin;
constantsHost_.varMax_ = real_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; }
Expand Down