Commit 87db636c authored by Alexander Alekhin's avatar Alexander Alekhin

Merge pull request #10657 from GlueCrow:mog2_init_fix

parents d84c7e51 c5c620ba
...@@ -770,6 +770,11 @@ public: ...@@ -770,6 +770,11 @@ public:
bool BackgroundSubtractorMOG2Impl::ocl_apply(InputArray _image, OutputArray _fgmask, double learningRate) bool BackgroundSubtractorMOG2Impl::ocl_apply(InputArray _image, OutputArray _fgmask, double learningRate)
{ {
bool needToInitialize = nframes == 0 || learningRate >= 1 || _image.size() != frameSize || _image.type() != frameType;
if( needToInitialize )
initialize(_image.size(), _image.type());
++nframes; ++nframes;
learningRate = learningRate >= 0 && nframes > 1 ? learningRate : 1./std::min( 2*nframes, history ); learningRate = learningRate >= 0 && nframes > 1 ? learningRate : 1./std::min( 2*nframes, history );
CV_Assert(learningRate >= 0); CV_Assert(learningRate >= 0);
...@@ -841,21 +846,21 @@ void BackgroundSubtractorMOG2Impl::apply(InputArray _image, OutputArray _fgmask, ...@@ -841,21 +846,21 @@ void BackgroundSubtractorMOG2Impl::apply(InputArray _image, OutputArray _fgmask,
{ {
CV_INSTRUMENT_REGION() CV_INSTRUMENT_REGION()
bool needToInitialize = nframes == 0 || learningRate >= 1 || _image.size() != frameSize || _image.type() != frameType;
if( needToInitialize )
initialize(_image.size(), _image.type());
#ifdef HAVE_OPENCL #ifdef HAVE_OPENCL
if (opencl_ON) if (opencl_ON)
{ {
CV_OCL_RUN(_fgmask.isUMat(), ocl_apply(_image, _fgmask, learningRate)) CV_OCL_RUN(_fgmask.isUMat(), ocl_apply(_image, _fgmask, learningRate))
opencl_ON = false; opencl_ON = false;
initialize(_image.size(), _image.type()); nframes = 0;
} }
#endif #endif
bool needToInitialize = nframes == 0 || learningRate >= 1 || _image.size() != frameSize || _image.type() != frameType;
if( needToInitialize )
initialize(_image.size(), _image.type());
Mat image = _image.getMat(); Mat image = _image.getMat();
_fgmask.create( image.size(), CV_8U ); _fgmask.create( image.size(), CV_8U );
Mat fgmask = _fgmask.getMat(); Mat fgmask = _fgmask.getMat();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment