Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can shadow tracking be disabled in BackgroundSubtractorMOG2?

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.

like image 699
IranianDude Avatar asked Nov 30 '25 18:11

IranianDude


2 Answers

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);
like image 181
user2029024 Avatar answered Dec 03 '25 09:12

user2029024


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; 
like image 43
IranianDude Avatar answered Dec 03 '25 09:12

IranianDude



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!