3

Im trying to disable shadow detection in openCV when using the BackgroundSubtractor algorithm BackgroundSubtractorMOG2. However even after setting bShadowDetection to false, the algorithm still seems to track shadows as foreground objects.

cv::BackgroundSubtractorMOG2 bg;
bg.nmixtures = 3;
bg.bShadowDetection = false;

I have tried to adjust different members of the BackgroundSubtractorMOG2 class in order to disable the shadow tracking with no chance. important class members of BackgroundSubtractorMOG2

Those that should be concerning shadow detection such as bShadowDetection or fTau seem to have no effect. The explanation in the documentation is also somehow not adequate.

IranianDude
  • 71
  • 1
  • 5
  • You can probably trace to the source code at opencv\modules\video\src\bgfg_gaussmix2.cpp and run the code by single step debugging. Have you tried setting the parameters from the constructor? – james Nov 06 '12 at 14:47

3 Answers3

2

For anyone who's actual using OpenCV-2.4.3, the other solution doesn't fit because the parameter variables are set to protected and not accessable.

But even the current OpenCV (2.4.3) API documentation is wrong (http://docs.opencv.org/modules/video/doc/motion_analysis_and_object_tracking.html#backgroundsubtractormog2) !

You have to create the BackgroundSubtractorMOG2 by the Algorithm::create() method and call the set-method with 'detectShadows' equals 0.

As an example use this:

using namespace cv;

Ptr<BackgroundSubtractorMOG2> bg =
    Algorithm::create<BackgroundSubtractorMOG2>("BackgroundSubtractor.MOG2");
bg->set("detectShadows", 0);
Jon Egerton
  • 40,401
  • 11
  • 97
  • 129
1

Thanks James for you response. By setting the nShadowDetection to 0, one can reduce the amount of shadow detected if anyone ever face the same issue.

mog2.nShadowDetection = 0; 
IranianDude
  • 71
  • 1
  • 5
0

I'm using OpenCV 2.4.2 and I had the same problem. Finally I was able to disable the shadow detection feature by using the code below:

   cv::BackgroundSubtractorMOG2 m_bg;
   m_bg.set("nmixtures",3);
   m_bg.set("detectShadows", false);
rkachach
  • 16,517
  • 6
  • 42
  • 66