Ask Your Question

Static Video Background Subtractor?

asked 2017-01-29 07:55:24 -0500

ginister gravatar image

Hi all,

Is it possible to have a background subtractor that doesn't compare to the previous frame? Here is my current code

- (void)processImage:(Mat&)image;
  Mat fg;
  if (sampleBG){
    bg = createBackgroundSubtractorMOG2(0,10);
    sampleBG = false; sampleHand = true;
  }else if (sampleHand){
    sampleHand = false; samplesExist = true;
  }else if (cameraOn && samplesExist){
    bg->apply(image, fg);
    image = fg;

Running this results in the background being subtracted, however once I move into the frame and stay in the same spot I fade away. Surely since I create bg on the first pass it should keep me as I am a difference from the original frame? Any advice?

edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted

answered 2017-01-29 08:21:16 -0500

Tetragramm gravatar image

Every time you call apply, it uses the new frame to learn the background. If you don't want it to learn, just set the learning rate to 0, as per the documentation for apply.

edit flag offensive delete link more


Perfect, I missed that argument - Exactly what I needed, thank you.

ginister gravatar imageginister ( 2017-01-29 08:26:51 -0500 )edit

Question Tools

1 follower


Asked: 2017-01-29 07:55:24 -0500

Seen: 160 times

Last updated: Jan 29 '17