-
Notifications
You must be signed in to change notification settings - Fork 5.8k
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
cuda::BackgroundSubtractorMOG2 gives different results after 4.2.0 #2941
Comments
For the same executable, I've observed differences in the output of cuda MOG2 between gtx1080 and rtx4000. Notably, the results from gtx1080 is visibly noisier. Frequently with almost square like blobs as outputs. Any chance that the generation of the NVIDIA card affects this too ? |
Chester-zZz
pushed a commit
to Chester-zZz/opencv_contrib
that referenced
this issue
Dec 11, 2023
6 tasks
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
System information (version)
Detailed description
Recently I'm working on some background subtractor algorithm using cuda. I first test the algorithm on opencv+opencv_contrib 3.4.4, the result is nice and stable. But when I deploy it on opencv+opencv_contrib 4.4.0, the subtractor gives more difference areas than 3.4.4.
After some search I found out:
There is an issue Multiple MOG2_GPU objects share the same parameter values opencv#5296, which report a bug about the subtractor, "Multiple MOG2_GPU objects share the same parameter values".
After 4 years, there is a PR resolves the issue: cuda_mog2_issue_5296 opencv#16090, which mainly modifed mog2.hpp and mog2.cpp, the new code moved the parameters to Constants struct instead of global.
In the new code of 16090, I found the bug:
The previous two funtions are called directly in constructor MOG2Impl::MOG2Impl. But when the fminf or fmaxf is called, varMin_ and varMax_ may still be undefined. For example, when setVarMin is called, varMin_ may be -99999999 or some strange number, and fminf may keep the number inside the object.
varMin_ and varMax_ will be uploaded to GPU in MOG2Impl::initialize. So I move the fminf and fmaxf operations into MOG2Impl::initialize, before cudaMemcpyAsync. Then everything works fine, the result is same with 3.4.4, at least I can not see any difference with my eyes. Code is modified like below:
The text was updated successfully, but these errors were encountered: