You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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 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.
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.
I am not an expert of background subtractor algorithm, I just found the bug based on understanding of C++ language.Here is a solution:
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:
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
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: