BackgroundsubtractorMOG2 result is not satisfactory.

asked 2015-08-18 01:19:50 -0600

I am using open cv to perform background subtraction. where i want to remove all moving objects from sequence of images. But at the end result image still contain some moving object. My code is below. Please suggest me how i can do it. thanks.

cv::Mat fgMaskMOG2;
cv::BackgroundSubtractorMOG2 pMOG2=cv::BackgroundSubtractorMOG2();

int i=1;
while (i<3) {
    NSString *path=[[NSBundle mainBundle]pathForResource:[NSString stringWithFormat:@"IMG_%d",i] ofType:@"JPG"];
   cv::Mat frame =cv::imread([path UTF8String]);
    pMOG2.operator()(frame, fgMaskMOG2);
    i++;![image description](http://)
}
cv::Mat output;
pMOG2.getBackgroundImage(output);
UIImage *imge=[self UIImageFromCVMat:fgMaskMOG2];
UIImage *imge2=[self UIImageFromCVMat:output];

Here are images which i am processing. image description image description image description Here is result which i am getting. image description

edit retag flag offensive close merge delete

Comments

i hope, you're not trying literally with those 4 images. the BackGroundSubtractor classes are meant to be used with a continuous stream, and it has to build a model over time.

berak gravatar imageberak ( 2015-08-18 01:29:45 -0600 )edit

Well i also tired with other set of images which are taken in a sequence and from one place with out moving. but results are same.

shahzaibiqbal gravatar imageshahzaibiqbal ( 2015-08-18 01:33:56 -0600 )edit

beside that i am using 2.4 version instead of 3.0 because when i use 3.0 i get bad memory exception in apply method. Do you any idea about this ?

shahzaibiqbal gravatar imageshahzaibiqbal ( 2015-08-18 01:35:03 -0600 )edit

"bad memory exception in apply method Do you any idea about this" - no.

and again, it will never work with just a few images. wrong tool for the job, then.

(also, just saying, the fgMaskMOG2 image is the result of that operation, not the getBackgroundImage() (which is generated from the internal model))

berak gravatar imageberak ( 2015-08-18 01:37:58 -0600 )edit

I see. thanks for the help. Any other suggested tool for such kind of task ?

shahzaibiqbal gravatar imageshahzaibiqbal ( 2015-08-18 01:41:39 -0600 )edit

what is your task, exactly ?

you probably need an image with plain background, and absdiff() later images

berak gravatar imageberak ( 2015-08-18 01:47:19 -0600 )edit

i want to get a background image from a sequence of images by removing all moving objects.

shahzaibiqbal gravatar imageshahzaibiqbal ( 2015-08-18 01:50:29 -0600 )edit